[pkg-opensc-commit] [opensc] 19/295: remove unused `scconf_entry`

Eric Dorland eric at moszumanska.debian.org
Sat Jun 24 21:11:12 UTC 2017


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository opensc.

commit 836842a6bb47b06b9f06d691a81621142ced7462
Author: Frank Morgner <frankmorgner at gmail.com>
Date:   Sun Jun 5 03:32:10 2016 +0200

    remove unused `scconf_entry`
---
 src/libopensc/libopensc.exports |   2 -
 src/scconf/Makefile.am          |   4 -
 src/scconf/scconf.c             | 303 ----------------------------------------
 src/scconf/scconf.h             |  28 ----
 src/scconf/test-conf.c          | 184 ------------------------
 5 files changed, 521 deletions(-)

diff --git a/src/libopensc/libopensc.exports b/src/libopensc/libopensc.exports
index c6a3c74..945afc5 100644
--- a/src/libopensc/libopensc.exports
+++ b/src/libopensc/libopensc.exports
@@ -20,13 +20,11 @@ scconf_list_strings_length
 scconf_list_toarray
 scconf_new
 scconf_parse
-scconf_parse_entries
 scconf_parse_string
 scconf_put_bool
 scconf_put_int
 scconf_put_str
 scconf_write
-scconf_write_entries
 _sc_asn1_decode
 _sc_asn1_encode
 sc_append_file_id
diff --git a/src/scconf/Makefile.am b/src/scconf/Makefile.am
index fa2e271..af5927d 100644
--- a/src/scconf/Makefile.am
+++ b/src/scconf/Makefile.am
@@ -6,12 +6,8 @@ EXTRA_DIST = Makefile.mak
 
 dist_noinst_DATA = README.scconf lex-parse.l
 noinst_HEADERS = internal.h scconf.h
-noinst_PROGRAMS = test-conf
 noinst_LTLIBRARIES = libscconf.la
 
 AM_CPPFLAGS = -I$(top_srcdir)/src
 
 libscconf_la_SOURCES = scconf.c parse.c write.c sclex.c 
-
-test_conf_SOURCES = test-conf.c
-test_conf_LDADD = libscconf.la $(top_builddir)/src/common/libcompat.la
diff --git a/src/scconf/scconf.c b/src/scconf/scconf.c
index 402b679..7fcc301 100644
--- a/src/scconf/scconf.c
+++ b/src/scconf/scconf.c
@@ -427,306 +427,3 @@ char *scconf_list_strdup(const scconf_list * list, const char *filler)
 		buf[strlen(buf) - strlen(filler)] = '\0';
 	return buf;
 }
-
-static scconf_block **getblocks(const scconf_context * config, const scconf_block * block, scconf_entry * entry)
-{
-	scconf_block **blocks = NULL, **tmp;
-
-	blocks = scconf_find_blocks(config, block, entry->name, NULL);
-	if (blocks) {
-		if (blocks[0] != NULL) {
-			if (config->debug) {
-				fprintf(stderr, "block found (%s)\n", entry->name);
-			}
-			return blocks;
-		}
-		free(blocks);
-		blocks = NULL;
-	}
-	if (scconf_find_list(block, entry->name) != NULL) {
-		if (config->debug) {
-			fprintf(stderr, "list found (%s)\n", entry->name);
-		}
-		tmp = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * 2);
-		if (!tmp) {
-			free(blocks);
-			return NULL;
-		}
-		blocks = tmp;
-		blocks[0] = (scconf_block *) block;
-		blocks[1] = NULL;
-	}
-	return blocks;
-}
-
-static int parse_entries(const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth);
-
-static int parse_type(const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth)
-{
-	void *parm = entry->parm;
-	size_t *len = (size_t *) entry->arg;
-	int (*callback_func) (const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth) =
-	(int (*)(const scconf_context *, const scconf_block *, scconf_entry *, int)) parm;
-	int r = 0;
-
-	if (config->debug) {
-		fprintf(stderr, "decoding '%s'\n", entry->name);
-	}
-	switch (entry->type) {
-	case SCCONF_CALLBACK:
-		if (parm) {
-			r = callback_func(config, block, entry, depth);
-		}
-		break;
-	case SCCONF_BLOCK:
-		if (parm) {
-			r = parse_entries(config, block, (scconf_entry *) parm, depth + 1);
-		}
-		break;
-	case SCCONF_LIST:
-		{
-			const scconf_list *val = scconf_find_list(block, entry->name);
-
-			if (!val) {
-				r = 1;
-				break;
-			}
-			if (parm) {
-				if (entry->flags & SCCONF_ALLOC) {
-					scconf_list *dest = NULL;
-
-					for (; val != NULL; val = val->next) {
-						if (!scconf_list_add(&dest, val->data)) {
-							r = 1;
-							break;
-						}
-					}
-					*((scconf_list **) parm) = dest;
-				} else {
-					*((const scconf_list **) parm) = val;
-				}
-			}
-			if (entry->flags & SCCONF_VERBOSE) {
-				char *buf = scconf_list_strdup(val, ", ");
-				printf("%s = %s\n", entry->name, buf);
-				free(buf);
-			}
-		}
-		break;
-	case SCCONF_BOOLEAN:
-		{
-			int val = scconf_get_bool(block, entry->name, 0);
-
-			if (parm) {
-				*((int *) parm) = val;
-			}
-			if (entry->flags & SCCONF_VERBOSE) {
-				printf("%s = %s\n", entry->name, val == 0 ? "false" : "true");
-			}
-		}
-		break;
-	case SCCONF_INTEGER:
-		{
-			int val = scconf_get_int(block, entry->name, 0);
-
-			if (parm) {
-				*((int *) parm) = val;
-			}
-			if (entry->flags & SCCONF_VERBOSE) {
-				printf("%s = %i\n", entry->name, val);
-			}
-		}
-		break;
-	case SCCONF_STRING:
-		{
-			const char *val = scconf_get_str(block, entry->name, NULL);
-			int vallen = val ? strlen(val) : 0;
-
-			if (!vallen) {
-				r = 1;
-				break;
-			}
-			if (parm) {
-				if (entry->flags & SCCONF_ALLOC) {
-					char **buf = (char **) parm;
-					*buf = malloc(vallen + 1);
-					if (*buf == NULL) {
-						r = 1;
-						break;
-					}
-					memset(*buf, 0, vallen + 1);
-					if (len) {
-						*len = vallen;
-					}
-					parm = *buf;
-				}
-				memcpy((char *) parm, val, vallen);
-			}
-			if (entry->flags & SCCONF_VERBOSE) {
-				printf("%s = %s\n", entry->name, val);
-			}
-		}
-		break;
-	default:
-		fprintf(stderr, "invalid configuration type: %d\n", entry->type);
-	}
-	if (r) {
-		fprintf(stderr, "decoding of configuration entry '%s' failed.\n", entry->name);
-		return r;
-	}
-	entry->flags |= SCCONF_PRESENT;
-	return 0;
-}
-
-static int parse_entries(const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth)
-{
-	int r, i, idx;
-	scconf_entry *e;
-	scconf_block **blocks = NULL;
-
-	if (config->debug) {
-		fprintf(stderr, "parse_entries called, depth %d\n", depth);
-	}
-	for (idx = 0; entry[idx].name; idx++) {
-		e = &entry[idx];
-		blocks = getblocks(config, block, e);
-		if (!blocks) {
-			if (!(e->flags & SCCONF_MANDATORY)) {
-				if (config->debug)
-					fprintf(stderr, "optional configuration entry '%s' not present\n",
-						e->name);
-				continue;
-			}
-			fprintf(stderr, "mandatory configuration entry '%s' not found\n", e->name);
-			return 1;
-		}
-		for (i = 0; blocks[i]; i++) {
-			r = parse_type(config, blocks[i], e, depth);
-			if (r) {
-				free(blocks);
-				return r;
-			}
-			if (!(e->flags & SCCONF_ALL_BLOCKS))
-				break;
-		}
-		free(blocks);
-	}
-	return 0;
-}
-
-int scconf_parse_entries(const scconf_context * config, const scconf_block * block, scconf_entry * entry)
-{
-	if (!entry)
-		return 1;
-	if (!block)
-		block = config->root;
-	return parse_entries(config, block, entry, 0);
-}
-
-static int write_entries(scconf_context * config, scconf_block * block, scconf_entry * entry, int depth);
-
-static int write_type(scconf_context * config, scconf_block * block, scconf_entry * entry, int depth)
-{
-	void *parm = entry->parm;
-	void *arg = entry->arg;
-	int (*callback_func) (scconf_context * config, scconf_block * block, scconf_entry * entry, int depth) =
-	(int (*)(scconf_context *, scconf_block *, scconf_entry *, int)) parm;
-	int r = 0;
-
-	if (config->debug) {
-		fprintf(stderr, "encoding '%s'\n", entry->name);
-	}
-	switch (entry->type) {
-	case SCCONF_CALLBACK:
-		if (parm) {
-			r = callback_func(config, block, entry, depth);
-		}
-		break;
-	case SCCONF_BLOCK:
-		if (parm) {
-			scconf_block *subblock;
-			const scconf_list *name = (const scconf_list *) arg;
-
-			subblock = scconf_block_add(config, block, entry->name, name);
-			r = write_entries(config, subblock, (scconf_entry *) parm, depth + 1);
-		}
-		break;
-	case SCCONF_LIST:
-		if (parm) {
-			const scconf_list *val = (const scconf_list *) parm;
-
-			scconf_item_add(config, block, NULL, SCCONF_ITEM_TYPE_VALUE, entry->name, val);
-			if (entry->flags & SCCONF_VERBOSE) {
-				char *buf = scconf_list_strdup(val, ", ");
-				printf("%s = %s\n", entry->name, buf);
-				free(buf);
-			}
-		}
-		break;
-	case SCCONF_BOOLEAN:
-		if (parm) {
-			const int val = * (int* ) parm;
-
-			scconf_put_bool(block, entry->name, val);
-			if (entry->flags & SCCONF_VERBOSE) {
-				printf("%s = %s\n", entry->name, val == 0 ? "false" : "true");
-			}
-		}
-		break;
-	case SCCONF_INTEGER:
-		if (parm) {
-			const int val = * (int*) parm;
-
-			scconf_put_int(block, entry->name, val);
-			if (entry->flags & SCCONF_VERBOSE) {
-				printf("%s = %i\n", entry->name, val);
-			}
-		}
-		break;
-	case SCCONF_STRING:
-		if (parm) {
-			const char *val = (const char *) parm;
-
-			scconf_put_str(block, entry->name, val);
-			if (entry->flags & SCCONF_VERBOSE) {
-				printf("%s = %s\n", entry->name, val);
-			}
-		}
-		break;
-	default:
-		fprintf(stderr, "invalid configuration type: %d\n", entry->type);
-	}
-	if (r) {
-		fprintf(stderr, "encoding of configuration entry '%s' failed.\n", entry->name);
-		return r;
-	}
-	entry->flags |= SCCONF_PRESENT;
-	return 0;
-}
-
-static int write_entries(scconf_context * config, scconf_block * block, scconf_entry * entry, int depth)
-{
-	int r, idx;
-	scconf_entry *e;
-
-	if (config->debug) {
-		fprintf(stderr, "write_entries called, depth %d\n", depth);
-	}
-	for (idx = 0; entry[idx].name; idx++) {
-		e = &entry[idx];
-		r = write_type(config, block, e, depth);
-		if (r) {
-			return r;
-		}
-	}
-	return 0;
-}
-
-int scconf_write_entries(scconf_context * config, scconf_block * block, scconf_entry * entry)
-{
-	if (!entry)
-		return 1;
-	if (!block)
-		block = config->root;
-	return write_entries(config, block, entry, 0);
-}
diff --git a/src/scconf/scconf.h b/src/scconf/scconf.h
index ddd414a..f6cdd9f 100644
--- a/src/scconf/scconf.h
+++ b/src/scconf/scconf.h
@@ -28,26 +28,6 @@
 extern "C" {
 #endif
 
-typedef struct _scconf_entry {
-	const char *name;
-	unsigned int type;
-	unsigned int flags;
-	void *parm;
-	void *arg;
-} scconf_entry;
-
-/* Entry flags */
-#define SCCONF_PRESENT		0x00000001
-#define SCCONF_MANDATORY	0x00000002
-#define SCCONF_ALLOC		0x00000004
-#define SCCONF_ALL_BLOCKS	0x00000008
-#define SCCONF_VERBOSE		0x00000010	/* For debugging purposes only */
-
-/* Entry types */
-#define SCCONF_CALLBACK		1
-#define SCCONF_BLOCK		2
-#define SCCONF_LIST		3
-
 #define SCCONF_BOOLEAN		11
 #define SCCONF_INTEGER		12
 #define SCCONF_STRING		13
@@ -106,20 +86,12 @@ extern int scconf_parse(scconf_context * config);
  */
 extern int scconf_parse_string(scconf_context * config, const char *string);
 
-/* Parse entries
- */
-extern int scconf_parse_entries(const scconf_context * config, const scconf_block * block, scconf_entry * entry);
-
 /* Write config to a file
  * If the filename is NULL, use the config->filename
  * Returns 0 = ok, else = errno
  */
 extern int scconf_write(scconf_context * config, const char *filename);
 
-/* Write configuration entries to block
- */
-extern int scconf_write_entries(scconf_context * config, scconf_block * block, scconf_entry * entry);
-
 /* Find a block by the item_name
  * If the block is NULL, the root block is used
  */
diff --git a/src/scconf/test-conf.c b/src/scconf/test-conf.c
deleted file mode 100644
index 41fc5df..0000000
--- a/src/scconf/test-conf.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2002
- *  Antti Tapaninen <aet at cc.hut.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
- */
-
-#include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include "scconf.h"
-
-#define ADD_TEST
-
-static int ldap_cb(const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth)
-{
-	scconf_entry ldap_entry[] =
-	{
-		{"ldaphost", SCCONF_STRING, SCCONF_VERBOSE, NULL, NULL},
-		{"ldapport", SCCONF_INTEGER, SCCONF_VERBOSE, NULL, NULL},
-		{"scope", SCCONF_INTEGER, SCCONF_VERBOSE, NULL, NULL},
-		{"binddn", SCCONF_STRING, SCCONF_VERBOSE, NULL, NULL},
-		{"passwd", SCCONF_STRING, SCCONF_VERBOSE, NULL, NULL},
-		{"base", SCCONF_STRING, SCCONF_VERBOSE, NULL, NULL},
-		{"attributes", SCCONF_LIST, SCCONF_VERBOSE, NULL, NULL},
-		{"filter", SCCONF_STRING, SCCONF_VERBOSE, NULL, NULL},
-		{NULL, 0, 0, NULL, NULL}
-	};
-	char *cardprefix = (char *) entry->arg;
-	char *str = scconf_list_strdup(block->name, " ");
-
-	if (!str)
-		return 1;
-	printf("LDAP entry[%s%s%s]\n", cardprefix ? cardprefix : "", cardprefix ? " " : "", str);
-	free(str);
-	if (scconf_parse_entries(config, block, ldap_entry) != 0) {
-		printf("scconf_parse_entries failed\n");
-		return 1;
-	}
-	return 0;		/* 0 for ok, 1 for error */
-}
-
-static int card_cb(const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth)
-{
-	char *str = scconf_list_strdup(block->name, " ");
-	scconf_entry card_entry[] =
-	{
-		{"ldap", SCCONF_CALLBACK, SCCONF_VERBOSE | SCCONF_ALL_BLOCKS, (void *) ldap_cb, str},
-		{NULL, 0, 0, NULL, NULL}
-	};
-
-	if (!str)
-		return 1;
-	printf("CARD entry[%s]\n", str);
-	if (scconf_parse_entries(config, block, card_entry) != 0) {
-		printf("scconf_parse_entries failed\n");
-		free(str);
-		return 1;
-	}
-	free(str);
-	return 0;		/* 0 for ok, 1 for error */
-}
-
-static int write_cb(scconf_context * config, scconf_block * block, scconf_entry * entry, int depth)
-{
-	scconf_put_str(block, entry->name, "inside write_cb();");
-	scconf_item_add(config, block, NULL, SCCONF_ITEM_TYPE_COMMENT, NULL, "# commentN");
-	return 0;		/* 0 for ok, 1 for error */
-}
-
-static int write_entries(scconf_context *conf, scconf_list *list)
-{
-	static int int42 = 42, int1 = 1;
-	scconf_entry subblock[] =
-	{
-		{"stringIT", SCCONF_STRING, SCCONF_VERBOSE, (void *) "sexy", NULL},
-		{"callback_str", SCCONF_CALLBACK, SCCONF_VERBOSE, (void *) write_cb, NULL},
-		{NULL, 0, 0, NULL, NULL}
-	};
-	scconf_entry wentry[] =
-	{
-		{"string", SCCONF_STRING, SCCONF_VERBOSE, (void *) "value1", NULL},
-		{"integer", SCCONF_INTEGER, SCCONF_VERBOSE, (void *) &int42, NULL},
-		{"sucks", SCCONF_BOOLEAN, SCCONF_VERBOSE,   (void *) &int1, NULL },
-		{"listN", SCCONF_LIST, SCCONF_VERBOSE, (void *) list, NULL},
-		{"blockN", SCCONF_BLOCK, SCCONF_VERBOSE, (void *) subblock, (void *) list},
-		{NULL, 0, 0, NULL, NULL}
-	};
-	return scconf_write_entries(conf, NULL, wentry);
-}
-
-int main(int argc, char **argv)
-{
-#ifdef ADD_TEST
-	scconf_block *foo_block = NULL;
-	scconf_item *foo_item = NULL;
-	scconf_list *foo_list = NULL;
-#endif
-	scconf_context *conf = NULL;
-	scconf_entry entry[] =
-	{
-		{"ldap", SCCONF_CALLBACK, SCCONF_VERBOSE | SCCONF_ALL_BLOCKS, (void *) ldap_cb, NULL},
-		{"card", SCCONF_CALLBACK, SCCONF_VERBOSE | SCCONF_ALL_BLOCKS, (void *) card_cb, NULL},
-		{NULL, 0, 0, NULL, NULL}
-	};
-	char *in = NULL, *out = NULL;
-	int r;
-
-	if (argc != 3) {
-		printf("Usage: test-conf <in.conf> <out.conf>\n");
-		return 1;
-	}
-	in = argv[argc - 2];
-	out = argv[argc - 1];
-
-	conf = scconf_new(in);
-	if (!conf) {
-		printf("scconf_new failed\n");
-		return 1;
-	}
-	if (scconf_parse(conf) < 1) {
-		printf("scconf_parse failed: %s\n", conf->errmsg);
-		scconf_free(conf);
-		return 1;
-	}
-	conf->debug = 1;
-	if (scconf_parse_entries(conf, NULL, entry) != 0) {
-		printf("scconf_parse_entries failed\n");
-		scconf_free(conf);
-		return 1;
-	}
-
-#ifdef ADD_TEST
-	scconf_list_add(&foo_list, "value1");
-	scconf_list_add(&foo_list, "value2");
-
-	foo_block = (scconf_block *) scconf_find_block(conf, NULL, "foo");
-	foo_block = scconf_block_add(conf, foo_block, "block1", foo_list);
-	foo_block = scconf_block_add(conf, foo_block, "block2", foo_list);
-
-	scconf_list_add(&foo_list, "value3");
-
-	/* this will not segfault as type SCCONF_ITEM_TYPE_COMMENT is used */
-	scconf_item_add(conf, foo_block, foo_item, SCCONF_ITEM_TYPE_COMMENT, NULL, "# comment1");
-	scconf_item_add(conf, foo_block, foo_item, SCCONF_ITEM_TYPE_VALUE, "list1", foo_list);
-	foo_block = NULL;
-	scconf_item_add(conf, foo_block, foo_item, SCCONF_ITEM_TYPE_BLOCK, "block3", (void *) scconf_find_block(conf, NULL, "foo"));
-	scconf_item_add(conf, foo_block, foo_item, SCCONF_ITEM_TYPE_VALUE, "list2", foo_list);
-	scconf_item_add(conf, foo_block, foo_item, SCCONF_ITEM_TYPE_COMMENT, NULL, "# comment2");
-
-	if (write_entries(conf, foo_list) != 0) {
-		printf("scconf_write_entries failed\n");
-		scconf_free(conf);
-		return 1;
-	}
-
-	scconf_list_destroy(foo_list);
-#endif
-
-	if ((r = scconf_write(conf, out)) != 0) {
-		printf("scconf_write: %s\n", strerror(r));
-	} else {
-		printf("Successfully rewrote file \"%s\" as \"%s\"\n", in, out);
-	}
-	scconf_free(conf);
-	return 0;
-}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/opensc.git



More information about the pkg-opensc-commit mailing list