OSSP CVS Repository

ossp - ossp-pkg/lmtp2nntp/lmtp2nntp_config.c 1.2
Not logged in
[Honeypot]  [Browse]  [Directory]  [Home]  [Login
[Reports]  [Search]  [Ticket]  [Timeline
  [Raw

ossp-pkg/lmtp2nntp/lmtp2nntp_config.c 1.2
/*
**  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 <sys/stat.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"

/* 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

void die(char *); //FIXME
void die(char *msg)
{
        printf("ERROR: %s", msg);
            exit(-1);
}

void dotconftest(void)
{
#if 0
    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
    };
#endif

    const char *filename = "example.conf";
    char *cpBuf;

    {
        struct stat sb;
        int fd;

        if (stat(filename, &sb) == -1)
            die("stat");
        if ((cpBuf = (char *)malloc((size_t)sb.st_size + 1)) == NULL)
            die("malloc");
        if ((fd = open(filename, O_RDONLY)) == -1)
            die("open");
        if (read(fd, (void *)cpBuf, (size_t)sb.st_size) != (ssize_t)sb.st_size)
            die("read");
        cpBuf[(int)sb.st_size] = '\0';
        if (close(fd) == -1)
            die("close");
    }
    //FIXME printf("DEBUG: *** 1 *** file as it was just read in ***\n%s***\n", cpBuf);

    {
        char *cpI; /* pointer to next character to be read */
        char *cpO; /* pointer to next character to be written when eliminating backslash+newline at a line continuation */
        char *cpL; /* pointer to start of line */
        int pline; /* current physical (disregarding line continuation) line number */
        int lline; /* current logical lines first physical line number */
        int eline; /* flag signaling empty or just whitespace-filled line */
        char c; /* current character */
        char p; /* previous character */
        int eof; /* flag signaling end of file detected */

        cpI = cpBuf;
        cpO = cpBuf;
        eof = FALSE;
        pline = 1;
        p = NUL; /* prefill previous character with fake value to avoid false
        line continuation detection when a newline is seen as the first
        character in the buffer */

        cpL = cpO;
        lline = pline;
        eline = TRUE;
        while(!eof) {
            c = *cpI++;
            *cpO++ = c;
            if (c == NUL)
                eof = TRUE;
            else
                if (!isspace(c))
                    eline = FALSE;
            if (eof || (c == '\n')) {
                pline++;
                if (!eof && (p == '\\')) { /* line continuation situation */
                    cpO-=2; /* need to remove both backslash+newline */
                }
                else {
                    if (!eline) { /* process logical line unless it's empty */
                        *(cpO-1) = NUL;
                        if (lline == (pline-1))
                            printf("DEBUG: line[%3d] = ***%s***\n", lline, cpL);
                        else
                            printf("DEBUG: [%3d-%3d] = ***%s***\n", lline, pline-1, cpL);
                        {
                            char *cp = cpL;
                            char *token;
                            char *value;

                            if ((token = str_token(&cp, " ", "\"'", "#", STR_STRIPQUOTES|STR_BACKSLASHESC)) == NULL)
                                printf("DEBUG: no token - comment only\n");
                            else {
                                printf("DEBUG:     token = ***%s***\n", token);
                                if ((value = str_token(&cp, "", "\"'", "#", STR_STRIPQUOTES|STR_BACKSLASHESC)) == NULL)
                                    printf("DEBUG: no value - section\n");
                                else
                                    printf("DEBUG:     value = ***%s***\n", value);
                            }
                        }
                    }
                    cpL = cpO;
                    lline = pline;
                    eline = TRUE;
                }
            }
            p = c;
        }
    }
}


CVSTrac 2.0.1