From ebb02c9a5cd5e47ff7b6dd70af8388783e313433 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 13 Jan 2011 16:22:26 -0800 Subject: [PATCH 1/1] fix compiler warning with bti_output_line Stupid, forgot to mark it as a void function. Signed-off-by: Greg Kroah-Hartman --- bti.c | 4 +- config.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 2 deletions(-) diff --git a/bti.c b/bti.c index 4b31cd5..f6479f8 100644 --- a/bti.c +++ b/bti.c @@ -284,8 +284,8 @@ static CURL *curl_init(void) } /* The final place data is sent to the screen/pty/tty */ -bti_output_line(struct session *session, xmlChar *user, xmlChar *id, - xmlChar *created, xmlChar *text) +void bti_output_line(struct session *session, xmlChar *user, xmlChar *id, + xmlChar *created, xmlChar *text) { if (session->verbose) printf("[%s] {%s} (%.16s) %s\n", user, id, created, text); diff --git a/config.c b/config.c index 829711a..03cd0aa 100644 --- a/config.c +++ b/config.c @@ -42,6 +42,123 @@ #include #include "bti.h" + + +/* + * get_key function + * + * Read a line from the config file and assign it a key and a value. + * + * This logic taken almost identically from taken from udev's rule file parsing + * logic in the file udev-rules.c, written by Kay Sievers and licensed under + * the GPLv2+. I hate writing parsers, so it makes sense to borrow working + * logic from those smarter than I... + */ +static int get_key(struct session *session, char *line, char **key, char **value) +{ + char *linepos; + char *temp; + char terminator; + + linepos = line; + if (linepos == NULL || linepos[0] == '\0') + return -1; + + /* skip whitespace */ + while (isspace(linepos[0]) || linepos[0] == ',') + linepos++; + if (linepos[0] == '\0') + return -1; + + *key = linepos; + + for (;;) { + linepos++; + if (linepos[0] == '\0') + return -1; + if (isspace(linepos[0])) + break; + if (linepos[0] == '=') + break; + } + + /* remember the end of the key */ + temp = linepos; + + /* skip whitespace after key */ + while (isspace(linepos[0])) + linepos++; + if (linepos[0] == '\0') + return -1; + + /* make sure this is a = operation */ + /* + * udev likes to check for += and == and lots of other complex + * assignments that we don't care about. + */ + if (linepos[0] == '=') + linepos++; + else + return -1; + + /* terminate key */ + temp[0] = '\0'; + + /* skip whitespace after opearator */ + while (isspace(linepos[0])) + linepos++; + if (linepos[0] == '\0') + return -1; + + /* + * if the value is quoted, then terminate on a ", otherwise space is + * the terminator. + * */ + if (linepos[0] == '"') { + terminator = '"'; + linepos++; + } else + terminator = ' '; + + /* get the value */ + *value = linepos; + + /* terminate */ + temp = strchr(linepos, terminator); + if (temp) { + temp[0] = '\0'; + temp++; + } else { + /* + * perhaps we just hit the end of the line, so there would not + * be a terminator, so just use the whole rest of the string as + * the value. + */ + } + printf("%s = %s\n", *key, *value); + return 0; +} + +typedef int (*config_function_callback)(struct session *session, char *value); + +struct config_table { + const char *key; + config_function_callback callback; +}; + + +int account_callback(struct session *session, char *value) +{ + return 0; +} + +static struct config_table config_table[] = { + { "account", account_callback }, + { NULL, NULL } +}; + + + void bti_parse_configfile(struct session *session) { FILE *config_file; @@ -69,6 +186,8 @@ void bti_parse_configfile(struct session *session) return; do { + char *key; + char *value; ssize_t n = getline(&line, &len, config_file); if (n < 0) break; @@ -87,6 +206,8 @@ void bti_parse_configfile(struct session *session) if (c[0] == '\0') continue; + get_key(session, line, &key, &value); + if (!strncasecmp(c, "account", 7) && (c[7] == '=')) { c += 8; if (c[0] != '\0') -- 2.39.5