Redo config parsing a bit.

No longer just call kore_string_split() on the line
but separate out the configuration directive and let
the appropriate callbacks parse things on their own.
This commit is contained in:
Joris Vink 2016-02-01 21:33:51 +01:00
parent 82a9e6ef59
commit c8484ee9ab
4 changed files with 315 additions and 422 deletions

View File

@ -515,6 +515,7 @@ long long kore_strtonum(const char *, int, long long, long long, int *);
int kore_base64_encode(u_int8_t *, u_int32_t, char **);
int kore_base64_decode(char *, u_int8_t **, u_int32_t *);
void *kore_mem_find(void *, size_t, void *, u_int32_t);
char *kore_text_trim(char *, size_t);
#if !defined(KORE_NO_HTTP)
void kore_websocket_handshake(struct http_request *,

View File

@ -97,7 +97,6 @@ static void cli_run_kore(void *);
static void cli_generate_certs(void);
static void cli_link_library(void *);
static void cli_compile_cfile(void *);
static char *cli_trim(char *, size_t);
static void cli_mkdir(const char *, int);
static int cli_dir_exists(const char *);
static int cli_file_exists(const char *);
@ -1047,7 +1046,7 @@ cli_buildopt_parse(const char *path)
{
FILE *fp;
struct buildopt *bopt;
char buf[BUFSIZ], *p, *t, *s;
char buf[BUFSIZ], *p, *t;
if ((fp = fopen(path, "r")) == NULL)
cli_fatal("cli_buildopt_parse: fopen(%s): %s", path, errno_s);
@ -1093,20 +1092,8 @@ cli_buildopt_parse(const char *path)
parse_option:
*(t)++ = '\0';
cli_trim(p, strlen(p));
cli_trim(t, strlen(t));
while (isspace(*p))
p++;
s = p + strlen(p) - 1;
while (isspace(*s))
*(s)-- = '\0';
while (isspace(*t))
t++;
s = t + strlen(t) - 1;
while (isspace(*s))
*(s)-- = '\0';
p = kore_text_trim(p, strlen(p));
t = kore_text_trim(t, strlen(t));
if (!strcasecmp(p, "cflags")) {
cli_buildopt_cflags(bopt, t);
@ -1370,21 +1357,6 @@ cli_cleanup_files(const char *spath)
printf("couldn't rmdir %s\n", spath);
}
static char *
cli_trim(char *string, size_t len)
{
char *end;
end = string + strlen(string) - 1;
while (isspace(*string))
string++;
while (isspace(*end) && end > string)
*(end)-- = '\0';
return (string);
}
static void
cli_fatal(const char *fmt, ...)
{

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@
#include <sys/time.h>
#include <ctype.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
@ -497,6 +498,21 @@ kore_mem_find(void *src, size_t slen, void *needle, u_int32_t len)
return (NULL);
}
char *
kore_text_trim(char *string, size_t len)
{
char *end;
end = string + strlen(string) - 1;
while (isspace(*string))
string++;
while (isspace(*end) && end > string)
*(end)-- = '\0';
return (string);
}
void
fatal(const char *fmt, ...)
{