Remove flag SCCONF_OPTIONAL, add SCCONF_MANDATORY

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@410 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
aet 2002-03-31 19:15:04 +00:00
parent 2fbf01e87d
commit b2a10c12e7
4 changed files with 30 additions and 25 deletions

View File

@ -445,7 +445,7 @@ static int parse_entries(scconf_context * config, const scconf_block * block, sc
r = 0;
blocks = getblocks(config, block, e);
if (!blocks) {
if (e->flags & SCCONF_OPTIONAL) {
if (!(e->flags & SCCONF_MANDATORY)) {
if (config->debug)
fprintf(stderr, "optional configuration entry '%s' not present\n",
e->name);

View File

@ -38,7 +38,7 @@ typedef struct _scconf_entry {
/* Entry flags */
#define SCCONF_PRESENT 0x00000001
#define SCCONF_OPTIONAL 0x00000002
#define SCCONF_MANDATORY 0x00000002
#define SCCONF_ALLOC 0x00000004
#define SCCONF_ALL_BLOCKS 0x00000008
#define SCCONF_VERBOSE 0x00000010 /* For debugging purposes only */

View File

@ -32,14 +32,14 @@ static int ldap_cb(scconf_context * config, const scconf_block * block, scconf_e
{
scconf_entry ldap_entry[] =
{
{"ldaphost", SCCONF_STRING, SCCONF_OPTIONAL | SCCONF_VERBOSE, NULL, NULL},
{"ldapport", SCCONF_INTEGER, SCCONF_OPTIONAL | SCCONF_VERBOSE, NULL, NULL},
{"scope", SCCONF_INTEGER, SCCONF_OPTIONAL | SCCONF_VERBOSE, NULL, NULL},
{"binddn", SCCONF_STRING, SCCONF_OPTIONAL | SCCONF_VERBOSE, NULL, NULL},
{"passwd", SCCONF_STRING, SCCONF_OPTIONAL | SCCONF_VERBOSE, NULL, NULL},
{"base", SCCONF_STRING, SCCONF_OPTIONAL | SCCONF_VERBOSE, NULL, NULL},
{"attributes", SCCONF_LIST, SCCONF_OPTIONAL | SCCONF_VERBOSE, NULL, NULL},
{"filter", SCCONF_STRING, SCCONF_OPTIONAL | SCCONF_VERBOSE, NULL, NULL},
{"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}
};
char *cardprefix = (char *) entry->arg;
@ -61,7 +61,7 @@ static int card_cb(scconf_context * config, const scconf_block * block, scconf_e
char *str = scconf_list_strdup(block->name, " ");
scconf_entry card_entry[] =
{
{"ldap", SCCONF_CALLBACK, SCCONF_OPTIONAL | SCCONF_VERBOSE | SCCONF_ALL_BLOCKS, (void *) ldap_cb, str},
{"ldap", SCCONF_CALLBACK, SCCONF_VERBOSE | SCCONF_ALL_BLOCKS, (void *) ldap_cb, str},
{NULL}
};
@ -82,8 +82,8 @@ int main(int argc, char **argv)
scconf_context *conf = NULL;
scconf_entry entry[] =
{
{"ldap", SCCONF_CALLBACK, SCCONF_OPTIONAL | SCCONF_VERBOSE | SCCONF_ALL_BLOCKS, (void *) ldap_cb},
{"card", SCCONF_CALLBACK, SCCONF_OPTIONAL | SCCONF_VERBOSE | SCCONF_ALL_BLOCKS, (void *) card_cb},
{"ldap", SCCONF_CALLBACK, SCCONF_VERBOSE | SCCONF_ALL_BLOCKS, (void *) ldap_cb},
{"card", SCCONF_CALLBACK, SCCONF_VERBOSE | SCCONF_ALL_BLOCKS, (void *) card_cb},
{NULL}
};
char *in = NULL, *out = NULL;

View File

@ -76,14 +76,14 @@ static int ldap_cb(scconf_context * config, const scconf_block * block, scconf_e
scldap_param_entry *lentry = (scldap_param_entry *) &ctx->entry[ctx->entries];
scconf_entry centry[] =
{
{"ldaphost", SCCONF_STRING, SCCONF_OPTIONAL | SCCONF_ALLOC, &lentry->ldaphost, NULL},
{"ldapport", SCCONF_INTEGER, SCCONF_OPTIONAL | SCCONF_ALLOC, &lentry->ldapport, NULL},
{"scope", SCCONF_INTEGER, SCCONF_OPTIONAL | SCCONF_ALLOC, &lentry->scope, NULL},
{"binddn", SCCONF_STRING, SCCONF_OPTIONAL | SCCONF_ALLOC, &lentry->binddn, NULL},
{"passwd", SCCONF_STRING, SCCONF_OPTIONAL | SCCONF_ALLOC, &lentry->passwd, NULL},
{"base", SCCONF_STRING, SCCONF_OPTIONAL | SCCONF_ALLOC, &lentry->base, NULL},
{"attributes", SCCONF_CALLBACK, SCCONF_OPTIONAL, (void *) attrs_cb, lentry},
{"filter", SCCONF_STRING, SCCONF_OPTIONAL | SCCONF_ALLOC, &lentry->filter, NULL},
{"ldaphost", SCCONF_STRING, SCCONF_ALLOC, &lentry->ldaphost, NULL},
{"ldapport", SCCONF_INTEGER, SCCONF_ALLOC, &lentry->ldapport, NULL},
{"scope", SCCONF_INTEGER, SCCONF_ALLOC, &lentry->scope, NULL},
{"binddn", SCCONF_STRING, SCCONF_ALLOC, &lentry->binddn, NULL},
{"passwd", SCCONF_STRING, SCCONF_ALLOC, &lentry->passwd, NULL},
{"base", SCCONF_STRING, SCCONF_ALLOC, &lentry->base, NULL},
{"attributes", SCCONF_CALLBACK, 0, (void *) attrs_cb, lentry},
{"filter", SCCONF_STRING, SCCONF_ALLOC, &lentry->filter, NULL},
{NULL}
};
char *ldapsuffix = NULL;
@ -92,13 +92,18 @@ static int ldap_cb(scconf_context * config, const scconf_block * block, scconf_e
if (ctx->entries >= SCLDAP_MAX_ENTRIES)
return 0; /* Hard limit reached, just return OK */
ldapsuffix = scconf_list_strdup(block->name, " ");
if (!ldapsuffix) {
return 1;
}
if (cardprefix) {
len = strlen(cardprefix) + 1;
}
len += strlen(ldapsuffix) + 1;
lentry->entry = malloc(len);
if (!lentry->entry)
if (!lentry->entry) {
free(ldapsuffix);
return 1;
}
memset(lentry->entry, 0, len);
snprintf(lentry->entry, len, "%s%s%s", cardprefix ? cardprefix : "", cardprefix ? " " : "", ldapsuffix);
free(ldapsuffix);
@ -119,7 +124,7 @@ static int card_cb(scconf_context * config, const scconf_block * block, scconf_e
cb_data *trans = (cb_data *) entry->arg;
scconf_entry card_entry[] =
{
{"ldap", SCCONF_CALLBACK, SCCONF_OPTIONAL | SCCONF_ALL_BLOCKS, (void *) ldap_cb, trans},
{"ldap", SCCONF_CALLBACK, SCCONF_ALL_BLOCKS, (void *) ldap_cb, trans},
{NULL}
};
@ -154,8 +159,8 @@ scldap_context *scldap_parse_parameters(const char *filename)
cb_data trans = {ctx, NULL};
scconf_entry entry[] =
{
{"ldap", SCCONF_CALLBACK, SCCONF_OPTIONAL | SCCONF_ALL_BLOCKS, (void *) ldap_cb, &trans},
{"card", SCCONF_CALLBACK, SCCONF_OPTIONAL | SCCONF_ALL_BLOCKS, (void *) card_cb, &trans},
{"ldap", SCCONF_CALLBACK, SCCONF_ALL_BLOCKS, (void *) ldap_cb, &trans},
{"card", SCCONF_CALLBACK, SCCONF_ALL_BLOCKS, (void *) card_cb, &trans},
{NULL}
};
ctx->conf = scconf_new(filename);