From 3f26e4b2cbc57331956933ec13f9494c75920587 Mon Sep 17 00:00:00 2001 From: YASUOKA Masahiko Date: Wed, 19 Sep 2012 08:58:58 +0000 Subject: remove files that became unused by new configuration syntax. --- usr.sbin/npppd/common/config_helper.c | 327 ------------------ usr.sbin/npppd/common/config_helper.h | 155 --------- usr.sbin/npppd/common/csvreader.c | 367 --------------------- usr.sbin/npppd/common/csvreader.h | 68 ---- usr.sbin/npppd/common/csvreader_test.c | 273 --------------- usr.sbin/npppd/common/properties.c | 566 -------------------------------- usr.sbin/npppd/common/properties.h | 59 ---- usr.sbin/npppd/common/properties_test.c | 182 ---------- 8 files changed, 1997 deletions(-) delete mode 100644 usr.sbin/npppd/common/config_helper.c delete mode 100644 usr.sbin/npppd/common/config_helper.h delete mode 100644 usr.sbin/npppd/common/csvreader.c delete mode 100644 usr.sbin/npppd/common/csvreader.h delete mode 100644 usr.sbin/npppd/common/csvreader_test.c delete mode 100644 usr.sbin/npppd/common/properties.c delete mode 100644 usr.sbin/npppd/common/properties.h delete mode 100644 usr.sbin/npppd/common/properties_test.c (limited to 'usr.sbin') diff --git a/usr.sbin/npppd/common/config_helper.c b/usr.sbin/npppd/common/config_helper.c deleted file mode 100644 index 30bab8488bb..00000000000 --- a/usr.sbin/npppd/common/config_helper.c +++ /dev/null @@ -1,327 +0,0 @@ -/* $OpenBSD: config_helper.c,v 1.4 2012/05/08 13:15:11 yasuoka Exp $ */ -/*- - * Copyright (c) 2009 Internet Initiative Japan Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -/* $Id: config_helper.c,v 1.4 2012/05/08 13:15:11 yasuoka Exp $ */ -#include -#include -#include -#include - -#include "properties.h" -#include "config_helper.h" -#include "debugmacro.h" - -#define KEYBUFSZ 512 - -/** - * This function concatenates given prefix and the give suffix for making - * configuration key (("prefix", "suffix") => "prefix.suffix"). The string - * returned by this function resides in a static memory area. - */ -const char * -config_key_prefix(const char *prefix, const char *suffix) -{ - static char keybuf[KEYBUFSZ]; - - strlcpy(keybuf, prefix, sizeof(keybuf)); - strlcat(keybuf, ".", sizeof(keybuf)); - strlcat(keybuf, suffix, sizeof(keybuf)); - - return keybuf; -} - -/** - * Retrieve the configuration value as a 'string' that is specified by - * given configuration key. - * @param _this The pointer to {@link ::properties} - * @param confKey configuration key name. - * @return pointer to the configuration value. If no configuration value - * exists then it returns NULL. - */ -const char * -config_str(struct properties *_this, const char *confKey) -{ - ASSERT(_this != NULL) - - return properties_get(_this, confKey); -} - -/** - * Retrieve the configuration value as a 'int' that is specified by - * given configuration key. - * @param _this The pointer to {@link ::properties} - * @param confKey configuration key name. - * @param defValue The default value. This function will return this - * value in case no configuration exists - */ -int -config_int(struct properties *_this, const char *confKey, int defValue) -{ - int rval, x; - const char *val; - - val = config_str(_this, confKey); - - if (val == NULL) - return defValue; - - x = sscanf(val, "%d", &rval); - - if (x != 1) - return defValue; - - return rval; -} - -/** - * Checks whether the configuration value equals given string. - * @param _this The pointer to {@link ::properties} - * @param confKey configuration key name. - * @param defValue The default value. This function will return this - * value in case no configuration exists - * @return return 1 if given string matches the configuration value, - * otherwise return 0. - */ -int -config_str_equal(struct properties *_this, const char *confKey, - const char *str, int defValue) -{ - const char *val; - - val = config_str(_this, confKey); - - if (val == NULL) - return defValue; - - return (strcmp(val, str) == 0)? 1 : 0; -} - -/** - * Checks whether the configuration value equals given string ignoring - * case. - * @param _this The pointer to {@link ::properties} - * @param confKey configuration key name. - * @param defValue The default value. This function will return this - * value in case no configuration exists - * @return return 1 if given string equals the configuration value, - * otherwise return 0. - */ -int -config_str_equali(struct properties *_this, const char *confKey, - const char *str, int defValue) -{ - const char *val; - - val = config_str(_this, confKey); - - if (val == NULL) - return defValue; - - return (strcasecmp(val, str) == 0)? 1 : 0; -} - -/*********************************************************************** - * Following functions are to get configuration value by given - * configuration key. At first the function will try to get the value - * by the key with the prefix, if it fails, then it will try to get the - * value by the key without the prefix. - * - * For example, we have following configuration - * - * pppoe.service_name: default_service - * PPPoE0.pppoe.service_name: my_service - * - * calling - * - * config_prefixed_str(prop, "PPPoE0", "service_name") - * - * returns "my_service". If - * - * PPPoE0.pppoe.service_name: my_service - * - * does not exist, then it returns "default_service". - * - * Functions that have fixed prefix can be generated by - * PREFIXED_CONFIG_FUNCTIONS macro that is defined in config_helper.h. - */ -const char * -config_prefixed_str(struct properties *_this, const char *prefix, const char *confKey) -{ - char keybuf[KEYBUFSZ]; - const char *val; - - if (prefix != NULL) { - snprintf(keybuf, sizeof(keybuf), "%s.%s", prefix, confKey); - val = config_str(_this, keybuf); - if (val != NULL) - return val; - } - - return config_str(_this, confKey); -} - -int -config_prefixed_int(struct properties *_this, const char *prefix, const char *confKey, int defValue) -{ - char keybuf[KEYBUFSZ]; - const char *val; - - if (prefix != NULL) { - snprintf(keybuf, sizeof(keybuf), "%s.%s", prefix, confKey); - val = config_str(_this, keybuf); - if (val != NULL) - return config_int(_this, keybuf, defValue); - } - - return config_int(_this, confKey, defValue); -} - -int -config_prefixed_str_equal(struct properties *_this, const char *prefix, const char *confKey, const char *str, - int defValue) -{ - char keybuf[KEYBUFSZ]; - const char *val; - - if (prefix != NULL) { - snprintf(keybuf, sizeof(keybuf), "%s.%s", prefix, confKey); - val = config_str(_this, keybuf); - if (val != NULL) - return config_str_equal(_this, keybuf, str, - defValue); - } - - return config_str_equal(_this, confKey, str, defValue); -} - -int -config_prefixed_str_equali(struct properties *_this, const char *prefix, - const char *confKey, const char *str, int defValue) -{ - char keybuf[KEYBUFSZ]; - const char *val; - - ASSERT(_this != NULL); - - if (prefix != NULL) { - snprintf(keybuf, sizeof(keybuf), "%s.%s", prefix, confKey); - val = config_str(_this, keybuf); - if (val != NULL) - return config_str_equali(_this, keybuf, str, - defValue); - } - - return config_str_equali(_this, confKey, str, defValue); -} - -/*********************************************************************** - * Following functions are to get configuration value by given - * configuration key. At first the function will try to get the value - * by the key with the prefix and given label, if it fail, then it will - * try to get the value by the key without the label. - * - * For example, we have following configuration - * - * ipcp.dns_primary: 192.168.0.1 - * ipcp.ipcp0.dns_primary: 192.168.0.2 - * - * calling - * - * config_named_prefix_str(prop, "ipcp", "ipcp0", "dns_primary"); - * - * will returns "192.168.0.2". If - * - * ipcp.ipcp0.dns_primary: 192.168.0.2 - * - * was not exists, then it returns "default_service". - * - * Functions that has fixed prefix can be generated by - * NAMED_PREFIXED_CONFIG_FUNCTIONS macro that is defined in - * config_helper.h. - ***********************************************************************/ -const char * -config_named_prefix_str(struct properties *_this, const char *prefix, - const char *name, const char *confKey) -{ - char keybuf[KEYBUFSZ]; - const char *val; - - if (name != NULL && name[0] != '\0') { - snprintf(keybuf, sizeof(keybuf), "%s.%s.%s", prefix, name, - confKey); - val = config_str(_this, keybuf); - if (val != NULL) - return val; - } - - snprintf(keybuf, sizeof(keybuf), "%s.%s", prefix, confKey); - return config_str(_this, keybuf); -} - -int -config_named_prefix_int(struct properties *_this, const char *prefix, - const char *name, const char *confKey, int defValue) -{ - char keybuf[KEYBUFSZ]; - const char *val; - - if (name != NULL && name[0] != '\0') { - snprintf(keybuf, sizeof(keybuf), "%s.%s.%s", prefix, name, - confKey); - val = config_str(_this, keybuf); - if (val != NULL) - return config_int(_this, keybuf, defValue); - } - - snprintf(keybuf, sizeof(keybuf), "%s.%s", prefix, confKey); - return config_int(_this, keybuf, defValue); -} - -int -config_named_prefix_str_equal(struct properties *_this, const char *prefix, - const char *name, const char *confKey, const char *str, int defValue) -{ - const char *val; - - val = config_named_prefix_str(_this, prefix, name, confKey); - if (val == NULL) - return defValue; - - return (strcmp(val, str) == 0)? 1 : 0; -} - -int -config_named_prefix_str_equali(struct properties *_this, const char *prefix, - const char *name, const char *confKey, const char *str, int defValue) -{ - const char *val; - - val = config_named_prefix_str(_this, prefix, name, confKey); - if (val == NULL) - return defValue; - - return (strcasecmp(val, str) == 0)? 1 : 0; -} diff --git a/usr.sbin/npppd/common/config_helper.h b/usr.sbin/npppd/common/config_helper.h deleted file mode 100644 index fe79781ce66..00000000000 --- a/usr.sbin/npppd/common/config_helper.h +++ /dev/null @@ -1,155 +0,0 @@ -/* $OpenBSD: config_helper.h,v 1.3 2012/05/08 13:15:11 yasuoka Exp $ */ -/*- - * Copyright (c) 2009 Internet Initiative Japan Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#ifndef CONFIG_HELPER_H -#define CONFIG_HELPER_H 1 - -#ifdef CONFIG_HELPER_NO_INLINE -#define INLINE -#else -#define INLINE inline -#endif - -#define CONFIG_DECL(fn_pre, basetype, prop) \ - INLINE const char *fn_pre ## _str(basetype *, const char *); \ - INLINE int fn_pre ## _int(basetype *, const char *, int); \ - INLINE int fn_pre ## _str_equal(basetype *, const char *, \ - const char *, int); \ - INLINE int fn_pre ## _str_equali(basetype *, const char *, \ - const char *, int); - -#define PREFIXED_CONFIG_DECL(fn_pre, basetype, prop, prefix) \ - INLINE const char *fn_pre ## _str(basetype *, const char *); \ - INLINE int fn_pre ## _int(basetype *, const char *, int); \ - INLINE int fn_pre ## _str_equal(basetype *, const char *, \ - const char *, int); \ - INLINE int fn_pre ## _str_equali(basetype *, const char *, \ - const char *, int); - -#define NAMED_PREFIX_CONFIG_DECL(fn_pre, basetype, prop, prefix, name) \ - INLINE const char *fn_pre ## _str(basetype *, const char *); \ - INLINE int fn_pre ## _int(basetype *, const char *, int); \ - INLINE int fn_pre ## _str_equal(basetype *, const char *, \ - const char *, int); \ - INLINE int fn_pre ## _str_equali(basetype *, const char *, \ - const char *, int); - -#define CONFIG_FUNCTIONS(fn_pre, basetype, prop) \ - INLINE const char * \ - fn_pre ## _str(basetype *_this, const char *confKey) { \ - return config_str(_this->prop, confKey); \ - } \ - INLINE int \ - fn_pre ## _int(basetype *_this, const char *confKey, \ - int defVal) { \ - return config_int(_this->prop, confKey, defVal); \ - } \ - int \ - fn_pre ## _str_equal(basetype *_this, const char *confKey, \ - const char *confVal, int defVal) { \ - return config_str_equal(_this->prop, confKey, confVal, \ - defVal); \ - } \ - int \ - fn_pre ## _str_equali(basetype *_this, const char *confKey, \ - const char *confVal, int defVal) { \ - return config_str_equali(_this->prop, confKey, confVal, \ - defVal); \ - } -#define PREFIXED_CONFIG_FUNCTIONS(fn_pre, basetype, prop, prefix) \ - INLINE const char * \ - fn_pre ## _str(basetype *_this, const char *confKey) { \ - return config_prefixed_str(_this->prop, _this->prefix, \ - confKey); \ - } \ - INLINE int \ - fn_pre ## _int(basetype *_this, const char *confKey, \ - int defVal) { \ - return config_prefixed_int(_this->prop, _this->prefix, \ - confKey, defVal); \ - } \ - int \ - fn_pre ## _str_equal(basetype *_this, const char *confKey, \ - const char *confVal, int defVal) { \ - return config_prefixed_str_equal(_this->prop, \ - _this->prefix, confKey, confVal, defVal); \ - } \ - int \ - fn_pre ## _str_equali(basetype *_this, const char *confKey, \ - const char *confVal, int defVal) { \ - return config_prefixed_str_equali(_this->prop, \ - _this->prefix, confKey, confVal, defVal); \ - } - -#define NAMED_PREFIX_CONFIG_FUNCTIONS(fn_pre, basetype, prop, prefix, \ - name) \ - INLINE const char * \ - fn_pre ## _str(basetype *_this, const char *confKey) { \ - return config_named_prefix_str(_this->prop, \ - prefix, _this->name, \ - confKey); \ - } \ - INLINE int \ - fn_pre ## _int(basetype *_this, const char *confKey, \ - int defVal) { \ - return config_named_prefix_int(_this->prop, prefix, \ - _this->name, confKey, defVal); \ - } \ - int \ - fn_pre ## _str_equal(basetype *_this, const char *confKey, \ - const char *confVal, int defVal) { \ - return config_named_prefix_str_equal(_this->prop, \ - prefix, _this->name, confKey, confVal, defVal); \ - } \ - int \ - fn_pre ## _str_equali(basetype *_this, const char *confKey, \ - const char *confVal, int defVal) { \ - return config_named_prefix_str_equali(_this->prop, \ - prefix, _this->name, confKey, confVal, defVal); \ - } - -#ifdef __cplusplus -extern "C" { -#endif - -const char *config_key_prefix (const char *, const char *); -const char *config_str (struct properties *, const char *); -int config_int (struct properties *, const char *, int); -int config_str_equal (struct properties *, const char *, const char *, int); -int config_str_equali (struct properties *, const char *, const char *, int); -const char *config_prefixed_str (struct properties *, const char *, const char *); -int config_prefixed_int (struct properties *, const char *, const char *, int); -int config_prefixed_str_equal (struct properties *, const char *, const char *, const char *, int); -int config_prefixed_str_equali (struct properties *, const char *, const char *, const char *, int); -const char *config_named_prefix_str (struct properties *, const char *, const char *, const char *); -int config_named_prefix_int (struct properties *, const char *, const char *, const char *, int); -int config_named_prefix_str_equal (struct properties *, const char *, const char *, const char *, const char *, int); -int config_named_prefix_str_equali (struct properties *, const char *, const char *, const char *, const char *, int); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr.sbin/npppd/common/csvreader.c b/usr.sbin/npppd/common/csvreader.c deleted file mode 100644 index c905ece84fd..00000000000 --- a/usr.sbin/npppd/common/csvreader.c +++ /dev/null @@ -1,367 +0,0 @@ -/* $OpenBSD: csvreader.c,v 1.4 2012/05/08 13:15:11 yasuoka Exp $ */ -/*- - * Copyright (c) 2009 Internet Initiative Japan Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -/* The original version is CSVReader.java */ -/* @file - * Subroutines to read CSV(RFC4180) - *
- *  csvreader *csv;
- *  const char **cols;
- *  char buf[1024];
- *
- *  csv = csvreader_create();
- *  while (fgets(buf, sizeof(buf), stdin) != NULL) {
- *	if (csvreader_parse(csv, buf) != CSVREADER_NO_ERROR) {
- *	    // error handling
- *	    break;
- *	}
- *	cols = csv_reader_get_column(csv)
- *	if (cols == NULL)
- *	    continue;
- *	// your code here.  col[0] is the first column.
- *   }
- *   if (csvreader_parse(csv, buf) == CSVREADER_NO_ERROR) {
- *	cols = csv_reader_get_column(csv)
- *	if (cols != NULL) {
- *	    // your code here.  col[0] is the first column.
- *	}
- *   } else {
- *	    // error handling
- *   }
- *   csvreader_destroy(csv);
- *
- */ -/* $Id: csvreader.c,v 1.4 2012/05/08 13:15:11 yasuoka Exp $ */ -#include -#include -#include - -#include "csvreader.h" - -struct _csvreader { - char *buffer; - const char **cols; - int cap; - int pos; - int start_pos; - int col_cap; - int col_pos; - int state; - int column_start_with_quote:1; -}; - -#define CSV_BUFSIZ 256 -#define CSV_COLSIZ 32 - -#define CSV_INIT 0 -#define CSV_IN_DATA 1 -#define CSV_WAIT_DELIM 2 -#define CSV_HAS_DQUOTE 3 -#define CSV_FLUSH_WAIT 4 - -#define DQUOTE '"' -#define COMMA ',' -#define CR '\r' -#define LF '\n' - -static int csvreader_buffer_append (csvreader *, const char *, int); -static int csvreader_flush_column (csvreader *); -static CSVREADER_STATUS csvreader_parse_flush0 (csvreader *, int); - -/** - * Make a cvsreader context and returns it. Return null if malloc() failed. - */ -csvreader * -csvreader_create(void) -{ - csvreader *_this; - - if ((_this = malloc(sizeof(csvreader))) == NULL) - return NULL; - memset(_this, 0, sizeof(*_this)); - _this->state = CSV_INIT; - - return _this; -} - - -/** - * Free a cvsreader context. - */ -void -csvreader_destroy(csvreader *_this) -{ - if (_this->buffer != NULL) - free(_this->buffer); - if (_this->cols != NULL) - free(_this->cols); - free(_this); -} - -/** - * get the number of parsed columns. - */ -int -csvreader_get_number_of_column(csvreader *_this) -{ - if (_this->state != CSV_FLUSH_WAIT) - return 0; - return _this->col_pos; -} - -/** - * get a parsed column. - */ -const char ** -csvreader_get_column(csvreader *_this) -{ - if (_this->state != CSV_FLUSH_WAIT) - return NULL; - - _this->col_pos = 0; - _this->pos = 0; - _this->start_pos = 0; - _this->state = CSV_INIT; - - return _this->cols; -} - -/** - * Reset a cvsreader context. - */ -void -csvreader_reset(csvreader *_this) -{ - _this->cap = 0; - _this->pos = 0; - _this->start_pos = 0; - _this->col_cap = 0; - _this->col_pos = 0; - _this->state = 0; - _this->column_start_with_quote = 0; -} - -/** - * Finish parsing of a column on the way. - *

- * Call this function when it's sure that there is no next line or the end - * of the CSV. - * It will return error when the parsing of the field isn't finished.

- */ -CSVREADER_STATUS -csvreader_parse_flush(csvreader *_this) -{ - return csvreader_parse_flush0(_this, 1); -} - -/** - * parse a line. - * - * @param a csvreader context - * @param a line to parse - */ -CSVREADER_STATUS -csvreader_parse(csvreader *_this, const char *line) -{ - int off, lline, append; - - lline = strlen(line); - - if (_this->state == CSV_FLUSH_WAIT) - return CSVREADER_HAS_PENDING_COLUMN; - - if (csvreader_buffer_append(_this, line, lline) != 0) - return CSVREADER_OUT_OF_MEMORY; - - for (off = 0; off < lline; off++) { - append = 1; - switch (_this->state) { - case CSV_INIT: - _this->state = CSV_IN_DATA; - if (line[off] == DQUOTE) { - _this->column_start_with_quote = 1; - break; - } - /* FALLTHROUGH */ - case CSV_IN_DATA: - if (_this->column_start_with_quote != 0) { - if (line[off] == DQUOTE) - _this->state = CSV_HAS_DQUOTE; - break; - } - if (line[off] == COMMA) { - append = 0; - csvreader_flush_column(_this); - } - if (_this->column_start_with_quote == 0 && - (line[off] == CR || line[off] == LF)) - goto eol; - break; - case CSV_HAS_DQUOTE: - if (line[off] == DQUOTE) { - _this->state = CSV_IN_DATA; - append = 0; - break; - } - _this->state = CSV_WAIT_DELIM; - /* FALLTHROUGH */ - case CSV_WAIT_DELIM: - if (line[off] == CR || line[off] == LF) - goto eol; - append = 0; - if (line[off] != COMMA) - return CSVREADER_PARSE_ERROR; - csvreader_flush_column(_this); - break; - } - if (append) - _this->buffer[_this->pos++] = line[off]; - } -eol: - - return csvreader_parse_flush0(_this, 0); -} - -static CSVREADER_STATUS -csvreader_parse_flush0(csvreader *_this, int is_final) -{ - if (_this->state == CSV_FLUSH_WAIT) - return CSVREADER_NO_ERROR; - switch (_this->state) { - case CSV_IN_DATA: - if (_this->column_start_with_quote != 0) { - if (is_final) - return CSVREADER_PARSE_ERROR; - /* wait next line */ - return CSVREADER_NO_ERROR; - } - /* FALLTHROUGH */ - case CSV_INIT: - if (is_final && _this->col_pos == 0) - return CSVREADER_NO_ERROR; - /* FALLTHROUGH */ - case CSV_HAS_DQUOTE: - case CSV_WAIT_DELIM: - csvreader_flush_column(_this); - _this->state = CSV_FLUSH_WAIT; - return CSVREADER_NO_ERROR; - } - return CSVREADER_PARSE_ERROR; -} - -/** - * Convert columns stored in char *[] to a CVS line string. - * - * @param cols columns to be converted. NULL means the end of the - * column. - * @param ncols number of columns - * @param buffer the output buffer to write a converted line. - * @param lbuffer the size of the output buffer. - */ -int -csvreader_toline(const char **cols, int ncols, char *buffer, int lbuffer) -{ - int i, j, off; - - off = 0; -#define checksize() if (off + 1 > lbuffer) { goto enobufs; } - for (i = 0; i < ncols && cols[i] != NULL; i++) { - if (i != 0) { - checksize(); - buffer[off++] = ','; - } - for (j = 0; cols[i][j] != '\0'; j++) { - if (j == 0) { - checksize(); - buffer[off++] = '"'; - } - if (cols[i][j] == '"') { - checksize(); - buffer[off++] = '"'; - } - checksize(); - buffer[off++] = cols[i][j]; - } - checksize(); - buffer[off++] = '"'; - } - checksize(); - buffer[off++] = '\0'; - - return 0; -enobufs: - return 1; -} - -static int -csvreader_buffer_append(csvreader *_this, const char *buf, int lbuf) -{ - int ncap; - char *nbuffer; - - if (_this->pos + lbuf > _this->cap) { - ncap = _this->cap + lbuf; - if ((ncap % CSV_BUFSIZ) != 0) - ncap += CSV_BUFSIZ - (ncap % CSV_BUFSIZ); - if ((nbuffer = realloc(_this->buffer, ncap)) == NULL) - return 1; - _this->cap = ncap; - _this->buffer = nbuffer; - } - - return 0; -} - -static int -csvreader_flush_column(csvreader *_this) -{ - int ncap; - const char **ncols; - - if (_this->col_pos + 1 >= _this->col_cap) { - ncap = _this->col_cap + CSV_COLSIZ; - if ((ncols = realloc(_this->cols, ncap * sizeof(char *))) - == NULL) - return CSVREADER_OUT_OF_MEMORY; - _this->col_cap = ncap; - _this->cols = ncols; - } - - if (_this->column_start_with_quote != 0) { - _this->start_pos++; - _this->buffer[_this->pos - 1] = '\0'; - } else { - _this->buffer[_this->pos++] = '\0'; - } - - _this->cols[_this->col_pos++] = _this->buffer + _this->start_pos; - _this->cols[_this->col_pos] = NULL; - _this->start_pos = _this->pos; - _this->column_start_with_quote = 0; - _this->state = CSV_INIT; - - return CSVREADER_NO_ERROR; -} diff --git a/usr.sbin/npppd/common/csvreader.h b/usr.sbin/npppd/common/csvreader.h deleted file mode 100644 index 6e0c3fbeaf4..00000000000 --- a/usr.sbin/npppd/common/csvreader.h +++ /dev/null @@ -1,68 +0,0 @@ -/* $OpenBSD: csvreader.h,v 1.3 2012/05/08 13:15:11 yasuoka Exp $ */ -/*- - * Copyright (c) 2009 Internet Initiative Japan Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#ifndef CSVREADER_H -#define CSVREADER_H 1 -/* $Id: csvreader.h,v 1.3 2012/05/08 13:15:11 yasuoka Exp $ */ - -/** status of cvsreader */ -typedef enum _CSVREADER_STATUS { - /** complete without any error */ - CSVREADER_NO_ERROR = 0, - /** - * A processing column exists. - *

- * This error occurs when parsing next line before getting a - * new coloumn by csvreader_get_columns(). - *

- */ - CSVREADER_HAS_PENDING_COLUMN = 10001, - /** Failed in memory allocation */ - CSVREADER_OUT_OF_MEMORY = 10002, - /** Parse Error */ - CSVREADER_PARSE_ERROR = 10003 -} CSVREADER_STATUS; - -typedef struct _csvreader csvreader; - -#ifdef __cplusplus -extern "C" { -#endif - -int csvreader_toline (const char **, int, char *, int); -csvreader * csvreader_create (void); -void csvreader_destroy (csvreader *); -void csvreader_reset (csvreader *); -const char ** csvreader_get_column (csvreader *); -int csvreader_get_number_of_column (csvreader *); -CSVREADER_STATUS csvreader_parse_flush (csvreader *); -CSVREADER_STATUS csvreader_parse (csvreader *, const char *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr.sbin/npppd/common/csvreader_test.c b/usr.sbin/npppd/common/csvreader_test.c deleted file mode 100644 index 40812e413e4..00000000000 --- a/usr.sbin/npppd/common/csvreader_test.c +++ /dev/null @@ -1,273 +0,0 @@ -/* $OpenBSD: csvreader_test.c,v 1.3 2012/05/08 13:15:11 yasuoka Exp $ */ -/*- - * Copyright (c) 2009 Internet Initiative Japan Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -/* - * cc -o csvreader_test csvreader.c csvreader_test.c - */ -/* $Id: csvreader_test.c,v 1.3 2012/05/08 13:15:11 yasuoka Exp $ */ -#include -#include -#include -#include "csvreader.h" - -#define ASSERT(x) \ - if (!(x)) { \ - fprintf(stderr, \ - "\nASSERT(%s) failed on %s() at %s:%d.\n" \ - , #x, __func__, __FILE__, __LINE__); \ - abort(); \ - } -#define countof(x) (sizeof((x)) / sizeof((x)[0])) -#define test(x) \ - { \ - fprintf(stderr, "%-10s ... ", #x); \ - fflush(stderr); \ - x(); \ - fprintf(stderr, "ok\n"); \ - } - - -static void -test01(void) -{ - int i; - CSVREADER_STATUS status; - const char ** column; - csvreader *csv; - char *csv_data[] = { - "hogehoge,fugafuga\n", - "hogehoge,fugafuga\n", - "hogehoge,fugafuga\n" - }; - - csv = csvreader_create(); - ASSERT(csv != NULL); - - for (i = 0; i < countof(csv_data); i++) { - status = csvreader_parse(csv, csv_data[i]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column != NULL); - ASSERT(strcmp(column[0], "hogehoge") == 0); - ASSERT(strcmp(column[1], "fugafuga") == 0); - ASSERT(column[2] == NULL); - } - csvreader_parse_flush(csv); - column = csvreader_get_column(csv); - ASSERT(column == NULL); - - csvreader_destroy(csv); -} - -static void -test02(void) -{ - CSVREADER_STATUS status; - const char ** column; - csvreader *csv; - char *csv_data[] = { - "\"hogehoge\",\"fugafuga\"\n", - "hogehoge,\"fugafuga\"\n", - "\"hogehoge\",fugafuga\n", - "\"hogehoge\",fuga\"fuga\n", - "\"hogehoge\",fuga\nfuga\n", - "\"hogehoge\",\"fuga\nfuga\"\n", - "\"hogehoge\",\"fuga\rfuga\"\n", - "\",fugafuga\n", - "hogehoge\",\n", - "\"hogehoge\n", - "hogehoge,fugafuga", - }; - - csv = csvreader_create(); - ASSERT(csv != NULL); - - status = csvreader_parse(csv, csv_data[0]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column != NULL); - ASSERT(strcmp(column[0], "hogehoge") == 0); - ASSERT(strcmp(column[1], "fugafuga") == 0); - ASSERT(column[2] == NULL); - - status = csvreader_parse(csv, csv_data[1]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column != NULL); - ASSERT(strcmp(column[0], "hogehoge") == 0); - ASSERT(strcmp(column[1], "fugafuga") == 0); - ASSERT(column[2] == NULL); - - status = csvreader_parse(csv, csv_data[2]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column != NULL); - ASSERT(strcmp(column[0], "hogehoge") == 0); - ASSERT(strcmp(column[1], "fugafuga") == 0); - ASSERT(column[2] == NULL); - - status = csvreader_parse(csv, csv_data[3]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column != NULL); - ASSERT(strcmp(column[0], "hogehoge") == 0); - ASSERT(strcmp(column[1], "fuga\"fuga") == 0); - ASSERT(column[2] == NULL); - - status = csvreader_parse(csv, csv_data[4]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column != NULL); - ASSERT(strcmp(column[0], "hogehoge") == 0); - ASSERT(strcmp(column[1], "fuga") == 0); - ASSERT(column[2] == NULL); - - status = csvreader_parse(csv, csv_data[5]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column != NULL); - ASSERT(strcmp(column[0], "hogehoge") == 0); - /* printf("**%s**\n", column[1]); */ - ASSERT(strcmp(column[1], "fuga\nfuga") == 0); - ASSERT(column[2] == NULL); - - status = csvreader_parse(csv, csv_data[6]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column != NULL); - ASSERT(strcmp(column[0], "hogehoge") == 0); - /* printf("**%s**\n", column[1]); */ - ASSERT(strcmp(column[1], "fuga\rfuga") == 0); - ASSERT(column[2] == NULL); - - status = csvreader_parse(csv, csv_data[7]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column == NULL); - status = csvreader_parse(csv, csv_data[8]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column != NULL); - ASSERT(strcmp(column[0], ",fugafuga\nhogehoge") == 0); - - csvreader_parse_flush(csv); - column = csvreader_get_column(csv); - ASSERT(column == NULL); - - status = csvreader_parse(csv, csv_data[9]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column == NULL); - - status = csvreader_parse_flush(csv); - ASSERT(status == CSVREADER_PARSE_ERROR); - column = csvreader_get_column(csv); - ASSERT(column == NULL); - - csvreader_reset(csv); - - status = csvreader_parse(csv, csv_data[10]); - ASSERT(status == CSVREADER_NO_ERROR); - column = csvreader_get_column(csv); - ASSERT(column != NULL); - ASSERT(strcmp(column[0], "hogehoge") == 0); - ASSERT(strcmp(column[1], "fugafuga") == 0); - - csvreader_destroy(csv); -} - -static void -test03(void) -{ - int i; - CSVREADER_STATUS status; - const char ** column; - csvreader *csv; - char *csv_data[] = { - "yasuoka,hogehoge,\"10.0.0.1\n", - "\n" - }; - - csv = csvreader_create(); - ASSERT(csv != NULL); - - status = csvreader_parse(csv, csv_data[0]); - ASSERT(status == CSVREADER_NO_ERROR); - - status = csvreader_parse_flush(csv); - ASSERT(status == CSVREADER_PARSE_ERROR); - column = csvreader_get_column(csv); - ASSERT(column == NULL); - - csvreader_destroy(csv); -} -static void -test04(void) -{ - int rval; - char line[8]; - const char *test[5]; - - memset(line, 0x55, sizeof(line)); - test[0] = "xxxxx"; - test[1] = NULL; - rval = csvreader_toline(test, 5, line, sizeof(line)); - ASSERT(rval == 0); - ASSERT(strcmp(line, "\"xxxxx\"") == 0); - - memset(line, 0x55, sizeof(line)); - test[0] = "xxxxxx"; - test[1] = NULL; - rval = csvreader_toline(test, 5, line, sizeof(line)); - ASSERT(rval != 0); - - memset(line, 0x55, sizeof(line)); - test[0] = "xx"; /* 5 */ - test[1] = "x"; /* 4 */ - test[2] = NULL; - rval = csvreader_toline(test, 5, line, sizeof(line)); - ASSERT(rval != 0); - - memset(line, 0x55, sizeof(line)); - test[0] = "x"; /* 5 */ - test[1] = "x"; /* 4 */ - test[2] = NULL; - rval = csvreader_toline(test, 5, line, sizeof(line)); - ASSERT(rval == 0); - ASSERT(strcmp(line, "\"x\",\"x\"") == 0); -} - -int -main(int argc, char *argv[]) -{ - test(test01); - test(test02); - test(test03); - test(test04); - - return 0; -} - diff --git a/usr.sbin/npppd/common/properties.c b/usr.sbin/npppd/common/properties.c deleted file mode 100644 index 065054748a7..00000000000 --- a/usr.sbin/npppd/common/properties.c +++ /dev/null @@ -1,566 +0,0 @@ -/*- - * Copyright (c) 2009 Internet Initiative Japan Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -/* - * $Id: properties.c,v 1.3 2010/07/02 21:20:57 yasuoka Exp $ - */ -/* LINTLIBRARY */ -#include -#include -#include -#include -#include -#include - -#include "hash.h" -#include "properties.h" -#include "debugmacro.h" - -struct properties { - hash_table *hash_tbl; -}; - -#ifdef _WIN32 -#define snprintf _snprintf -#define u_int32_t unsigned long -#endif - -#ifndef MAX -#define MAX(m,n) (((m) > (n))? (m) : (n)) -#endif -#ifndef MIN -#define MIN(m,n) (((m) < (n))? (m) : (n)) -#endif - -static int continue_line __P((const char *)); -static char *convert_in_save __P((const char *)); -static void convert_in_load __P((char *)); -static uint32_t str_hash __P((const void *, int)); -static const char * properties_put0(struct properties *, const char *, const char *, int); - -static void chomp __P((char *)); -static char * trim __P((char *)); -static const char * skip_space __P((const char *)); - -/** - * Create properties object - * - * @param sz size of hash (sould be prime number) - * @return pointer to created object - */ -struct properties * -properties_create(int sz) -{ - struct properties *_this; - - if ((_this = (struct properties *)malloc(sizeof(struct properties))) - == NULL) - return NULL; - memset(_this, 0, sizeof(struct properties)); - - if ((_this->hash_tbl = hash_create( - (int (*)(const void *, const void *))strcmp, - str_hash, sz)) == NULL) { - free(_this); - return NULL; - } - - return _this; -} - -/** - * get property value by key - * - * @param _this pointer to properties object - * @param key property key - * @returns property value - */ -const char * -properties_get(struct properties *_this, const char *key) -{ - hash_link *hl; - - if ((hl = hash_lookup(_this->hash_tbl, key)) != NULL) - return hl->item; - return NULL; -} - -/** - * remove property entry. - * - * @param _this pointer to properties object - * @param key property key - */ -void -properties_remove(struct properties *_this, const char *key) -{ - char *key0; - hash_link *hl; - - if ((hl = hash_lookup(_this->hash_tbl, key)) == NULL) - return; - - key0 = /* NOSTRICT */(char *)hl->key; - - hash_delete(_this->hash_tbl, key, 1); - free(key0); -} - -/** - * remove all items from the properties. - * - * @param _this pointer to properties object - */ -void -properties_remove_all(struct properties *_this) -{ - char *key0; - hash_link *hl; - - for (hl = hash_first(_this->hash_tbl); hl != NULL; - hl = hash_next(_this->hash_tbl)) { - key0 = /* NOSTRICT */(char *)hl->key; - hash_delete(_this->hash_tbl, hl->key, 1); - free(key0); - } -} - -/** - * put all items of 'props' properties to the properties. - * - * @param _this pointer to properties object - */ -void -properties_put_all(struct properties *_this, struct properties *props) -{ - hash_link *hl; - - for (hl = hash_first(props->hash_tbl); hl != NULL; - hl = hash_next(props->hash_tbl)) { - properties_put(_this, hl->key, hl->item); - } -} - -/** - * put(add) property entry. - * - * @param _this pointer to properties object - * @param key property key - * @param value property value - * @return pointer to property value that is stored in hash table. - */ -const char * -properties_put(struct properties *_this, const char *key, const char *value) -{ - return properties_put0(_this, key, value, 1); -} - -static const char * -properties_put0(struct properties *_this, const char *key, const char *value, - int do_trim) -{ - char *key0 = NULL, *value0 = NULL; - char *key1 = NULL, *value1 = NULL; - - if (key[0] == '\0') - return NULL; - - if ((key0 = strdup(key)) == NULL) - goto exception; - - key1 = key0; - if (do_trim) - key1 = trim(key1); - if (key1[0] == '\0') - goto exception; - - if ((value0 = strdup(value)) == NULL) - goto exception; - value1 = value0; - if (do_trim) { - value1 = trim(value1); - if (value1 != value0) { - /* value1 must point the beginning of the buffer */ - if ((value1 = strdup(value1)) == NULL) - goto exception; - free(value0); - value0 = value1; - } - } - properties_remove(_this, key1); - if (hash_insert(_this->hash_tbl, key1, value1) != 0) - goto exception; - - return value; -exception: - if (key0 != NULL) - free(key0); - if (value0 != NULL) - free(value0); - return NULL; -} - -/** - * Destroy properties object. - * @param _this pointer to properties object - */ -void -properties_destroy(struct properties *_this) -{ - if (_this->hash_tbl != NULL) { - properties_remove_all(_this); - hash_free(_this->hash_tbl); - _this->hash_tbl = NULL; - } - free(_this); -} - -/** - * get first key value of properties. - * - * @param _this pointer to properties object - * @return the first key value of properties. - * @see #properties_next_key - */ -const char * -properties_first_key(struct properties *_this) -{ - hash_link *hl; - - hl = hash_first(_this->hash_tbl); - if (hl != NULL) - return hl->key; - return NULL; -} - -/** - * get next key value of properties. - * - * @param _this pointer to properties object - * @return the next key value of properties. - * @see properties_first_key - */ -const char * -properties_next_key(struct properties *_this) -{ - hash_link *hl; - - hl = hash_next(_this->hash_tbl); - if (hl != NULL) - return hl->key; - return NULL; -} - -/** - * Store this object to a file - * - * @param _this pointer to properties object - * @param fp FILE stream to store. - * @return returns 0 in succeed. - */ -int -properties_save(struct properties *_this, FILE *fp) -{ - char *value; - const char *key; - - for (key = properties_first_key(_this); key != NULL; - key = properties_next_key(_this)) { - if ((value = convert_in_save(properties_get(_this, key))) - == NULL) - return -1; - - fprintf(fp, "%s: %s\n", key, value); - free(value); - } - return 0; -} - -static int -continue_line(const char *line) -{ - int eol; - int slash_cnt = 0; - - eol = strlen(line); - - while (--eol > 0) { - if (*(line + eol) == '\\') - slash_cnt++; - else - break; - } - if (slash_cnt % 2 == 1) - return 1; - - return 0; -} - -static char * -convert_in_save(const char *value) -{ - size_t outsz = 128; - int i, j; - char *out, *out0; - - if ((out = (char *)malloc(outsz)) == NULL) - return NULL; - - for (i = 0, j = 0; value[i] != '\0'; i++) { - if (j + 2 > outsz) { - if ((out0 = (char *)realloc(out, outsz * 2)) == NULL) { - free(out); - return NULL; - } - out = out0; - outsz *= 2; - } - switch (value[i]) { - case '\n': out[j++] = '\\'; out[j++] = 'n'; break; - case '\r': out[j++] = '\\'; out[j++] = 'r'; break; - case '\t': out[j++] = '\\'; out[j++] = 't'; break; - case '\\': out[j++] = '\\'; out[j++] = '\\'; break; - default: out[j++] = value[i]; break; - } - } - out[j] = '\0'; - - return out; -} - -static void -convert_in_load(char *value) -{ - int i, j; - - for (i = 0, j = 0; value[i] != '\0'; i++, j++) { - if (value[i] == '\\') { - switch (value[++i]) { - case '\\': value[j] = '\\'; continue; - case 'r': value[j] = '\r'; continue; - case 'n': value[j] = '\n'; continue; - case 't': value[j] = '\t'; continue; - default: break; - } - } - value[j] = value[i]; - } - value[j] = '\0'; -} - -/* - * Load properties from the given file pointer(FILE) using the given charset - * decoder. We use EUC-JP encoding internally. - * - * @param _this pointer to the properties object. - * @param fp FILE stream to load. - * @return return 0 in succeed. - */ -int -properties_load(struct properties *_this, FILE *fp) -{ - char *key, *value, *delim; - char buf0[BUFSIZ]; - size_t linesz = 128, linelen; - - int lineoff = 0, hasnl, linecont; - char *line = NULL, *line0, *line1; - - if ((line = (char *)malloc(linesz)) == NULL) - goto fail; - - linecont = 0; - while (fgets(buf0, sizeof(buf0), fp) != NULL) { - hasnl = 0; - linelen = strlen(buf0); - if (linelen > 0 && buf0[linelen - 1] == '\n') { - hasnl = 1; - chomp(buf0); - } - if (linecont || (lineoff == 0)) - line0 = (char *)skip_space(buf0); - else - line0 = buf0; - linelen = strlen(line0); - while (lineoff + linelen + 128 > linesz) { - if ((line1 = realloc(line, linesz * 2)) - == NULL) - goto fail; - line = line1; - linesz *= 2; - } - memcpy(line + lineoff, line0, linelen); - line[lineoff + linelen] = '\0'; - lineoff += linelen; - - linecont = 0; - if (!hasnl) - continue; - - if (continue_line(line0)) { - lineoff--; /* delete \(backslash) */ - linecont = 1; - continue; - } - lineoff = 0; - if (*line == '#') - continue; - key = line; - - for (delim = key; *delim != '\0'; delim++) { - if (*delim == '=' || *delim == ':') - break; - } - if (*delim == '\0') - continue; - - *delim = '\0'; - value = trim(delim + 1); - key = trim(key); - - convert_in_load(value); - - properties_put0(_this, key, value, 0); - - lineoff = 0; - } - if (line != NULL) - free(line); - return 0; -fail: - if (line != NULL) - free(line); - - return -1; -} - -static uint32_t -str_hash(const void *ptr, int sz) -{ - u_int32_t hash = 0; - int i, len; - const char *str; - - str = ptr; - len = strlen(str); - for (i = 0; i < len; i++) - hash = hash*0x1F + str[i]; - hash = (hash << 16) ^ (hash & 0xffff); - - return hash % sz; -} - -#define ISCRLF(x) ((x) == '\r' || (x) == '\n') -#define ISSPACE(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || \ - (x) == '\n') -static const char * -skip_space(s) - const char *s; -{ - const char *r; - - for (r = s; *r != '\0' && ISSPACE(*r); r++) - ;; /* skip */ - return r; -} - -static char * -trim(s) - char *s; -{ - char *r; - char *t; - - r = /* NOSTRICT */(char *)skip_space(s); - for (t = r + strlen(r) - 1; r <= t; t--) { - if (ISSPACE(*t)) - *t = '\0'; - else - break; - } - return r; -} - -static void -chomp(s) - char *s; -{ - char *t; - - for (t = s + strlen(s) - 1; s <= t; t--) { - if (ISCRLF(*t)) - *t = '\0'; - else - break; - } -} - -#if PROPGET_CMD -#include - -static void usage __P((void)); - -static void usage(void) -{ - fprintf(stderr, "usage: propgetcmd prop_file prop_key [prop_key ..]\n"); -} - -int -main(int argc, char *argv[]) -{ - const char *k; - struct properties *prop; - FILE *fp; - - argc--; - argv++; - - if (argc < 2) { - usage(); - return 1; - } - - if ((fp = fopen(*argv, "r")) == NULL) { - perror(*argv); - return 1; - } - argc--; - argv++; - - if ((prop = properties_create(127)) == NULL) { - perror("properties_create() failed"); - return 1; - } - properties_load(prop, fp); - - while (argc--) { - if (properties_get(prop, *argv) != NULL) - printf("%s\n", properties_get(prop, *argv)); - - } - fclose(fp); - properties_destroy(prop); -} -#endif diff --git a/usr.sbin/npppd/common/properties.h b/usr.sbin/npppd/common/properties.h deleted file mode 100644 index 05b798a5724..00000000000 --- a/usr.sbin/npppd/common/properties.h +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * Copyright (c) 2009 Internet Initiative Japan Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#ifndef PROPERTIES_H -#define PROPERTIES_H 1 - -struct properties; - -#ifndef __P -#if defined(__STDC__) || defined(_MSC_VER) -#define __P(x) x -#else -#define __P(x) () -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -struct properties *properties_create __P((int)); -const char *properties_get __P((struct properties *, const char *)); -void properties_remove __P((struct properties *, const char *)); -void properties_remove_all __P((struct properties *)); -const char *properties_put __P((struct properties *, const char *, const char *)); -void properties_put_all __P((struct properties *, struct properties *)); -void properties_destroy __P((struct properties *)); -const char *properties_first_key __P((struct properties *)); -const char *properties_next_key __P((struct properties *)); -int properties_save __P((struct properties *, FILE *)); -int properties_load __P((struct properties *, FILE *)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr.sbin/npppd/common/properties_test.c b/usr.sbin/npppd/common/properties_test.c deleted file mode 100644 index dc34bcd4c64..00000000000 --- a/usr.sbin/npppd/common/properties_test.c +++ /dev/null @@ -1,182 +0,0 @@ -/*- - * Copyright (c) 2009 Internet Initiative Japan Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -/* - * cc -o properties_test -DNO_KANJI=1 properties_test.c properties.c hash.c - * - * ./properties_test - */ -#include -#include -#include -#include - -#include "properties.h" - -#define MIN(m,n) ((m) < (n))? (m) : (n) -#define TEST(f) \ - { \ - printf("%-10s .. ", #f); \ - f(); \ - printf("ok\n"); \ - } - -#define ASSERT(x) \ - if (!(x)) { \ - fprintf(stderr, \ - "\nASSERT(%s) failed on %s() at %s:%d.\n" \ - , #x, __func__, __FILE__, __LINE__); \ - abort(); \ - } - -static void -set_and_get(const char *key, const char *value) -{ - FILE *f; - struct properties *props; - - ASSERT((f = fopen("test.properties", "w")) != NULL); - ASSERT((props = properties_create(512)) != NULL); - ASSERT(properties_put(props, key, value) != NULL); - ASSERT(properties_save(props, f) == 0); - ASSERT(fclose(f) == 0); - properties_destroy(props); - - ASSERT((props = properties_create(512)) != NULL); - ASSERT((f = fopen("test.properties", "r")) != NULL); - ASSERT(properties_load(props, f) == 0); - ASSERT(strcmp(properties_get(props, key), value) == 0); - properties_destroy(props); - - ASSERT(fclose(f) == 0); -} - -void -test0(void) -{ - set_and_get("hoge", "hogehoge"); - set_and_get("hoge", "hogehogehogehoge"); - set_and_get("hoge", "hogehogehogehogehogehoge"); - set_and_get("hoge", "hogehogehogehogehogehogehogehoge"); - set_and_get("hoge", "hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge"); - set_and_get("hoge", "hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge"); - set_and_get("hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge", "hogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoehogehogehogehgoe"); -} -static void test1() -{ - /* 1024 bytes */ - set_and_get("pptpd.listener_in", "PPTP 10.10.10.50 PPTP 100.100.100.100 PPTP 100.100.100.101 PPTP 100.100.100.102 PPTP 100.100.100.103 PPTP 100.100.100.104 PPTP 100.100.100.105 PPTP 100.100.100.106 PPTP 100.100.100.107 PPTP 100.100.100.108 PPTP 100.100.100.109 PPTP 100.100.100.110 PPTP 100.100.100.111 PPTP 100.100.100.112 PPTP 100.100.100.113 PPTP 100.100.100.114 PPTP 100.100.100.115 PPTP 100.100.100.116 PPTP 100.100.100.117 PPTP 100.100.100.118 PPTP 100.100.100.119 PPTP 100.100.100.120 PPTP 100.100.100.121 PPTP 100.100.100.122 PPTP 100.100.100.123 PPTP 100.100.100.124 PPTP 100.100.100.125 PPTP 100.100.100.126 PPTP 100.100.100.127 PPTP 100.100.100.128 PPTP 100.100.100.129 PPTP 100.100.100.130 PPTP 100.100.100.131 PPTP 100.100.100.132 PPTP 100.100.100.133 PPTP 100.100.100.134 PPTP 100.100.100.135 PPTP 100.100.100.136 PPTP 100.100.100.137 PPTP 100.100.100.138 PPTP 100.100.100.139 PPTP 100.100.100.140 PPTP 100.100.100.141 PPTP 100.100.100.142 PPTP 100.100.100.143 PPTP 100.100.100.144 PPTP 100.100.100.145 PPTP 100.100.100.146 PPTP 100.100.100.147 PPTP 100.100.100.148 PPTP 100.100.100.149 PPTP 100.100.100.150 PPTP 100.100.100.151 PPTP 100.100.100.152 PPTP 100.100.100.153 PPTP 100.100.100.154 PPTP 100.100.100.155 PPTP 100.100.100.156 PPTP 100.100.100.157 PPTP 100.100.100.158 PPTP 100.100.100.159 PPTP 100.100.100.160 PPTP 100.100.100.161 PPTP 100.100.100.162 PPTP 100.100.100.163 PPTP 100.100.100.164 PPTP 100.100.100.165 PPTP 100.100.100.166 PPTP 100.100.100.167 PPTP 100.100.100.168 PPTP 100.100.100.169 PPTP 100.100.100.170 PPTP 100.100.100.171 PPTP 100.100.100.172 PPTP 100.100.100.173 PPTP 100.100.100.174 PPTP 100.100.100.175 PPTP 100.100.100.176 PPTP 100.100.100.177 PPTP 100.100.100.178 PPTP 100.100.100.179 PPTP 100.100.100.180 PPTP 100.100.100.181 PPTP 100.100.100.182 PPTP 100.100.100.183 PPTP 100.100.100.184 PPTP 100.100.100.185 PPTP 100.100.100.186 PPTP 100.100.100.187 PPTP 100.100.100.188 PPTP 100.100.100.189 PPTP 100.100.100.190 PPTP 100.100.100.191 PPTP 100.100.100.192 PPTP 100.100.100.193 PPTP 100.100.100.194 PPTP 100.100.100.195 PPTP 100.100.100.196 PPTP 100.100.100.197 PPTP 100.100.100.198 PPTP 100.100.100.200"); - set_and_get("pptpd.ip4_allow", "pptpd.ip4_allow: 192.168.10.1/32 192.168.10.2/32 192.168.10.3/32 192.168.10.4/32 192.168.10.5/32 192.168.10.6/32 192.168.10.7/32 192.168.10.8/32 192.168.10.9/32 192.168.10.10/32 192.168.10.11/32 192.168.10.12/32 192.168.10.13/32 192.168.10.14/32 192.168.10.15/32 192.168.10.16/32 192.168.10.17/32 192.168.10.18/32 192.168.10.19/32 192.168.10.20/32 192.168.10.21/32 192.168.10.22/32 192.168.10.23/32 192.168.10.24/32 192.168.10.25/32 192.168.10.26/32 192.168.10.27/32 192.168.10.28/32 192.168.10.29/32 192.168.10.30/32 192.168.10.31/32 192.168.10.32/32 192.168.10.33/32 192.168.10.34/32 192.168.10.35/32 192.168.10.36/32 192.168.10.37/32 192.168.10.38/32 192.168.10.39/32 192.168.10.40/32 192.168.10.41/32 192.168.10.42/32 192.168.10.43/32 192.168.10.44/32 192.168.10.45/32 192.168.10.46/32 192.168.10.47/32 192.168.10.48/32 192.168.10.49/32 192.168.10.50/32 192.168.10.51/32 192.168.10.52/32 192.168.10.53/32 192.168.10.54/32 192.168.10.55/32 192.168.10.56/32 192.168.1.57/32 192.168.1.58/32 192.168.1.59/32 192.168.10.60/32 192.168.10.61/32 192.168.10.62/32 192.168.10.63/32 192.168.10.64/32 192.168.10.65/32 192.168.10.66/32 192.168.10.67/32 192.168.10.68/32 192.168.10.69/32 192.168.10.70/32 192.168.10.71/32 192.168.10.72/32 192.168.10.73/32 192.168.10.74/32 192.168.10.75/32 192.168.10.76/32 192.168.10.77/32 192.168.10.78/32 192.168.10.79/32 192.168.10.80/32 192.168.10.81/32 192.168.10.82/32 192.168.10.83/32 192.168.10.84/32 192.168.10.85/32 192.168.10.86/32 192.168.10.87/32 192.168.10.88/32 192.168.10.89/32 192.168.10.90/32 192.168.10.91/32 192.168.10.92/32 192.168.10.93/32 192.168.10.94/32 192.168.10.95/32 192.168.10.96/32 192.168.10.97/32 192.168.10.98/32 192.168.10.99/32 192.168.10.100/32 192.168.10.101/32 192.168.10.102/32 192.168.10.103/32 192.168.10.104/32 192.168.10.105/32 192.168.10.106/32 192.168.10.107/32 192.168.10.108/32 192.168.10.109/32 192.168.10.110/32 192.168.10.111/32 192.168.10.112/32 192.168.10.113/32 192.168.10.114/32 192.168.10.115/32 192.168.10.116/32 192.168.10.117/32 192.168.10.118/32 192.168.1.119/32 192.168.1.120/32 192.168.1.121/32"); - -} - - -static void test2() -{ - set_and_get("hogehoge", "hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge"); - set_and_get("hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge", "hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge"); - set_and_get("hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge", "hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge"); - set_and_get("hogehoge", "hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge"); - set_and_get("hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge", "hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge"); -} -void -test3(void) -{ - FILE *f; - struct properties *props; - - ASSERT((f = fopen("test.properties", "w")) != NULL); - ASSERT((props = properties_create(512)) != NULL); - ASSERT(properties_put(props, " ", "HOGEHOGE") == NULL); - ASSERT(properties_put(props, "", "HOGEHOGE") == NULL); - ASSERT(properties_put(props, "HOGEHOGE", "") != NULL); - ASSERT(properties_save(props, f) == 0); - ASSERT(fclose(f) == 0); -} - -static int test4_off = 0; -static char test4_buf[] = - "test1: Net\\\n" - " BSD\n" - "test2: Made in\\\n" - " \\ Japan\n" - "test3: bbb\\\n" - " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaa \n" - "test4: \\r\n" - ; - -static int -test4_read_fn(void *cookie, char *buf, int len) -{ - int rval; - - rval = MIN(len, sizeof(test4_buf) - test4_off); - if (rval == 0) - return 0; /* EOF */ - memcpy(buf, test4_buf + test4_off, rval); - test4_off += rval; - - return rval; -} - - -static void -test4() -{ - FILE *fp; - struct properties *props; - const char *val; - - - fp = fropen(NULL, test4_read_fn); - ASSERT((props = properties_create(512)) != NULL); - ASSERT((properties_load(props, fp)) == 0); - fclose(fp); - - val = properties_get(props, "test1"); - ASSERT(val != NULL); - ASSERT(strcmp(val, "NetBSD") == 0); - - val = properties_get(props, "test2"); - ASSERT(val != NULL); - ASSERT(strcmp(val, "Made in Japan") == 0); - val = properties_get(props, "test3"); - ASSERT(val != NULL); - ASSERT(strcmp(val, "bbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaa") == 0); - - val = properties_get(props, "test4"); - ASSERT(val != NULL); - ASSERT(strcmp(val, "\r") == 0); -} - -int -main(int argc, char *argv[]) -{ - TEST(test0); - TEST(test1); - TEST(test2); - TEST(test3); - TEST(test4); -} -- cgit v1.2.3