ossp-pkg/lmtp2nntp/lmtp2nntp_config.c
1.1
/*
** Copyright (c) 2001-2002 The OSSP Project <http://www.ossp.org/>
** Copyright (c) 2001-2002 Cable & Wireless Deutschland <http://www.cw.com/de/>
**
** This file is part of OSSP lmtp2nntp, an LMTP speaking local
** mailer which forwards mails as Usenet news articles via NNTP.
** It can be found at http://www.ossp.org/pkg/lmtp2nntp/.
**
** 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.0 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 file; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
** USA, or contact the OSSP project <ossp@ossp.org>.
**
** lmtp2nntp.c: LMTP to NNTP configuration parsing
*/
#include <stdlib.h>
#include <stdio.h>
// #include <unistd.h>
// #include <errno.h>
// #include <string.h>
// #include <fcntl.h>
// #include <sys/utsname.h>
// #include <sys/time.h>
// #include <sys/types.h>
// #include <sys/wait.h>
// #include <sys/stat.h>
// #include <signal.h>
// #include <pwd.h>
/* third party (included) */
// #include "lmtp2nntp_argz.h"
// #include "lmtp2nntp_shpat.h"
// #include "lmtp2nntp_daemon.h"
// #include "lmtp2nntp_popt.h"
#include "lmtp2nntp_dotconf.h"
/* third party (linked in) */
// #include "str.h"
// #include "l2.h"
// #include "var.h"
/* library version check (compile-time) */
#define L2_VERSION_HEX_REQ 0x001200
#define L2_VERSION_STR_REQ "0.1.0"
#define STR_VERSION_HEX_REQ 0x009206
#define STR_VERSION_STR_REQ "0.9.6"
#ifdef L2_VERSION_HEX
#if L2_VERSION_HEX < L2_VERSION_HEX_REQ
#error "require a newer version of OSSP L2"
#endif
#endif
#ifdef STR_VERSION_HEX
#if STR_VERSION_HEX < STR_VERSION_HEX_REQ
#error "require a newer version of OSSP Str"
#endif
#endif
/* own headers */
#include "lmtp2nntp_global.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(HAVE_DMALLOC_H) && defined(DMALLOC)
#include "dmalloc.h"
#endif
#include "lmtp2nntp_lmtp.h"
#include "lmtp2nntp_nntp.h"
#include "lmtp2nntp_msg.h"
#include "sa.h"
#define _LMTP2NNTP_VERSION_C_AS_HEADER_
#include "lmtp2nntp_version.c"
#undef _LMTP2NNTP_VERSION_C_AS_HEADER_
#ifndef FALSE
#define FALSE (1 != 1)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
#ifndef NUL
#define NUL '\0'
#endif
const char *foo(command_t *, context_t *);
int bar(configfile_t *, int, long, const char *);
const char *quux(command_t *, unsigned long);
const char *foo(command_t *cmd, context_t *_ctx)
{
int *foodata = (int *)_ctx;
int i;
printf("DEBUG: callbck %s:%ld: %s:", cmd->configfile->filename, cmd->configfile->line, cmd->name);
for (i = 0; i < cmd->arg_count; i++)
;//printf("[%d=***%s***] ", i, cmd->data.list[i]);
printf("---%lx---%d---", foodata, (*foodata)++);
printf("\n");
return NULL;
}
int bar(configfile_t *configfile, int type, long dc_errno, const char *msg)
{
printf("DEBUG: handler type=%d, dc_errno=%ld, msg=***%s***\n", type, dc_errno, msg);
return 0; /* 0=continue, 1=abort */
}
const char *quux(command_t *cmd, unsigned long mask)
{
printf("DEBUG: checker %s:%ld: %s: ", cmd->configfile->filename, cmd->configfile->line, cmd->name);
printf("[mask=%lx]", mask);
printf("\n");
if ((strcmp(cmd->name, "client") == 0) && (mask = 4))
return "Nasenbaer!";
return NULL;
}
enum configcontext
{
CTX_DAEMON = 1<<0,
CTX_SERVER = 1<<1,
CTX_CLIENT = 1<<2,
CTX_GATEWAY = 1<<3,
CTX_MESSAGE = 1<<4
};
void dotconftest(void)
{
configfile_t *configfile;
static int foodata;
static const configoption_t options[] = {
{ "<daemon>", ARG_NONE, foo, NULL, CTX_ALL },
{ "childsmax", ARG_STR, foo, NULL, CTX_DAEMON },
{ "daemonize", ARG_STR, foo, NULL, CTX_DAEMON },
{ "pidfile", ARG_STR, foo, NULL, CTX_DAEMON },
{ "acl", ARG_STR, foo, NULL, CTX_DAEMON },
{ "bind", ARG_STR, foo, NULL, CTX_DAEMON },
{ "</daemon>", ARG_NONE, foo, NULL, CTX_DAEMON },
{ "<server>", ARG_NONE, foo, NULL, CTX_ALL },
{ "timeoutaccept", ARG_STR, foo, NULL, CTX_SERVER },
{ "timeoutread", ARG_STR, foo, NULL, CTX_SERVER },
{ "timeoutwrite", ARG_STR, foo, NULL, CTX_SERVER },
{ "size", ARG_STR, foo, NULL, CTX_SERVER },
{ "mailfrom", ARG_STR, foo, NULL, CTX_SERVER },
{ "nodename", ARG_STR, foo, NULL, CTX_SERVER },
{ "</server>", ARG_NONE, foo, NULL, CTX_SERVER },
{ "<client>", ARG_NONE, foo, NULL, CTX_ALL },
{ "client", ARG_STR, foo, NULL, CTX_CLIENT },
{ "destination", ARG_STR, foo, NULL, CTX_CLIENT },
{ "operationmode", ARG_STR, foo, NULL, CTX_CLIENT },
{ "timeoutconnect", ARG_STR, foo, NULL, CTX_CLIENT },
{ "timeoutread", ARG_STR, foo, NULL, CTX_CLIENT },
{ "timeoutwrite", ARG_STR, foo, NULL, CTX_CLIENT },
{ "</client>", ARG_NONE, foo, NULL, CTX_CLIENT },
{ "<gateway>", ARG_NONE, foo, NULL, CTX_ALL },
{ "groupmode", ARG_STR, foo, NULL, CTX_GATEWAY },
{ "l2spec", ARG_STR, foo, NULL, CTX_GATEWAY },
{ "uid", ARG_STR, foo, NULL, CTX_GATEWAY },
{ "newsgroup", ARG_STR, foo, NULL, CTX_GATEWAY },
{ "</gateway>", ARG_NONE, foo, NULL, CTX_GATEWAY },
{ "<message>", ARG_NONE, foo, NULL, CTX_ALL },
{ "headervalue", ARG_STR, foo, NULL, CTX_MESSAGE },
{ "restrictheader", ARG_STR, foo, NULL, CTX_MESSAGE },
{ "</message>", ARG_NONE, foo, NULL, CTX_MESSAGE },
LAST_OPTION
};
foodata = 1000;
printf("---%lx---%d---", &foodata, foodata);
configfile = dotconf_create("example.conf", options, &foodata, CASE_INSENSITIVE);
if (!configfile) {
fprintf(stderr, "Error opening config file\n");
return;
}
configfile->errorhandler = (dotconf_errorhandler_t)bar;
configfile->contextchecker = (dotconf_contextchecker_t)quux;
if (dotconf_command_loop(configfile) == 0)
fprintf(stderr, "Error reading config file\n");
dotconf_cleanup(configfile);
}