OSSP CVS Repository

ossp - Check-in [1540]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1540
Date: 2002-Jan-10 11:37:38 (local)
2002-Jan-10 10:37:38 (UTC)
User:thl
Branch:
Comment: replaced dotconf library with own code and str_token
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/Makefile.in      1.35 -> 1.36     3 inserted, 3 deleted
ossp-pkg/lmtp2nntp/example.conf      1.2 -> 1.3     8 inserted, 8 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_config.c      1.1 -> 1.2     92 inserted, 55 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp_dotconf.c      1.2->removed
ossp-pkg/lmtp2nntp/lmtp2nntp_dotconf.h      1.2->removed

ossp-pkg/lmtp2nntp/Makefile.in 1.35 -> 1.36

--- Makefile.in  2002/01/09 13:54:25     1.35
+++ Makefile.in  2002/01/10 10:37:38     1.36
@@ -44,9 +44,9 @@
 POD2MAN     = pod2man
 
 PROG = lmtp2nntp
-HDRS = lmtp2nntp_global.h lmtp2nntp_daemon.h lmtp2nntp_lmtp.h lmtp2nntp_nntp.h lmtp2nntp_argz.h lmtp2nntp_shpat.h lmtp2nntp_msg.h lmtp2nntp_popt.h lmtp2nntp_dotconf.h lmtp2nntp_config.h
-SRCS = lmtp2nntp_main.c   lmtp2nntp_daemon.c lmtp2nntp_lmtp.c lmtp2nntp_nntp.c lmtp2nntp_argz.c lmtp2nntp_shpat.c lmtp2nntp_msg.c lmtp2nntp_popt.c lmtp2nntp_dotconf.c lmtp2nntp_config.c lmtp2nntp_version.c 
-OBJS = lmtp2nntp_main.o   lmtp2nntp_daemon.o lmtp2nntp_lmtp.o lmtp2nntp_nntp.o lmtp2nntp_argz.o lmtp2nntp_shpat.o lmtp2nntp_msg.o lmtp2nntp_popt.o lmtp2nntp_dotconf.o lmtp2nntp_config.o lmtp2nntp_version.o
+HDRS = lmtp2nntp_global.h lmtp2nntp_daemon.h lmtp2nntp_lmtp.h lmtp2nntp_nntp.h lmtp2nntp_argz.h lmtp2nntp_shpat.h lmtp2nntp_msg.h lmtp2nntp_popt.h lmtp2nntp_config.h
+SRCS = lmtp2nntp_main.c   lmtp2nntp_daemon.c lmtp2nntp_lmtp.c lmtp2nntp_nntp.c lmtp2nntp_argz.c lmtp2nntp_shpat.c lmtp2nntp_msg.c lmtp2nntp_popt.c lmtp2nntp_config.c lmtp2nntp_version.c 
+OBJS = lmtp2nntp_main.o   lmtp2nntp_daemon.o lmtp2nntp_lmtp.o lmtp2nntp_nntp.o lmtp2nntp_argz.o lmtp2nntp_shpat.o lmtp2nntp_msg.o lmtp2nntp_popt.o lmtp2nntp_config.o lmtp2nntp_version.o
 
 SUBDIRS = @SUBDIR_STR@ @SUBDIR_L2@ @SUBDIR_SA@ @SUBDIR_VAR@
 


ossp-pkg/lmtp2nntp/example.conf 1.2 -> 1.3

--- example.conf 2002/01/09 13:54:25     1.2
+++ example.conf 2002/01/10 10:37:38     1.3
@@ -9,13 +9,13 @@
     childsmax       10                              #see -C aka --childsmax
     daemonize       yes                             #see -D aka --daemonize
                                                     #    -K aka --kill is not available in the configfile
-    pidfile         "/tmp/pid"                      #see -P aka --pidfile
+    pidfile         /tmp/pid                        #see -P aka --pidfile
     acl             10/8                            #see -a aka --acl
     acl             172.16/12
     acl             192.168/16
     acl             127.0.0.1/32     
     bind            127.0.0.1:12345                 #see -b aka --bind, use IPv4:port
-    #bind           "/tmp/uds:600"                  #    UNIX domain socket path:permissions 
+    #bind           /tmp/uds:600                    #    UNIX domain socket path:permissions 
 </daemon>
 
 <server> #LMTP
@@ -23,8 +23,8 @@
     timeoutread     10 
     timeoutwrite    10 
     size            555000                          #see -s aka --size
-    mailfrom        "any.*@example\.org"            #see -m aka --mailfrom
-    nodename        "gateway.example.com"           #see -n aka --nodename
+    mailfrom        any.*@example\.org              #see -m aka --mailfrom
+    nodename        gateway.example.com             #see -n aka --nodename
 </server>
 
 <client> #NNTP, multiple sections allowed
@@ -41,15 +41,15 @@
 
                                                     #    -l is obsolete since v1.2, see l2spec
                                                     #    -V is obsolete since v1.2; remove the "buffer" channel from l2spec
-    l2spec          prefix(prefix="%%b %%d %%H:%%M:%%S <%%L> lmtp2nntp[%%P]: ",timezone=local) \
+    l2spec          "prefix(prefix="%%b %%d %%H:%%M:%%S <%%L> lmtp2nntp[%%P]: ",timezone=local) \
                        -> buffer(size=65536) \
-                       -> file(path=%s,append=1,perm=%d) \
+                       -> file(path=%s,append=1,perm=%d)" \
                                                     #    -l aka --l2spec
 
     uid             gate                            #see -u aka --uid
                                                     #    -v aka --version is not available in the configfile
-    newsgroup       "test"
-    newsgroup       "alt.test"                      #see man page for information about newsgroup
+    newsgroup       test
+    newsgroup       alt.test                        #see man page for information about newsgroup
 </gateway>
 
 <message>


ossp-pkg/lmtp2nntp/lmtp2nntp_config.c 1.1 -> 1.2

--- lmtp2nntp_config.c   2002/01/09 13:54:25     1.1
+++ lmtp2nntp_config.c   2002/01/10 10:37:38     1.2
@@ -26,6 +26,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <sys/stat.h>
 // #include <unistd.h>
 // #include <errno.h>
 // #include <string.h>
@@ -43,10 +44,9 @@
 // #include "lmtp2nntp_shpat.h"
 // #include "lmtp2nntp_daemon.h"
 // #include "lmtp2nntp_popt.h"
-#include "lmtp2nntp_dotconf.h"
 
 /* third party (linked in) */
-// #include "str.h"
+#include "str.h"
 // #include "l2.h"
 // #include "var.h"
 
@@ -93,52 +93,16 @@
 #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)
+void die(char *); //FIXME
+void die(char *msg)
 {
-    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;
+        printf("ERROR: %s", msg);
+            exit(-1);
 }
 
-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;
+#if 0
     static const configoption_t options[] = {
         { "<daemon>",       ARG_NONE, foo, NULL, CTX_ALL     },
         { "childsmax",      ARG_STR,  foo, NULL, CTX_DAEMON  },
@@ -175,21 +139,94 @@
         { "</message>",     ARG_NONE, foo, NULL, CTX_MESSAGE },
         LAST_OPTION
     };
+#endif
 
-    foodata = 1000;
-    printf("---%lx---%d---", &foodata, foodata);
+    const char *filename = "example.conf";
+    char *cpBuf;
 
-    configfile = dotconf_create("example.conf", options, &foodata, CASE_INSENSITIVE);
-    if (!configfile) {
-        fprintf(stderr, "Error opening config file\n");
-        return;
+    {
+        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");
     }
-    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");
+    //FIXME printf("DEBUG: *** 1 *** file as it was just read in ***\n%s***\n", cpBuf);
 
-    dotconf_cleanup(configfile);
+    {
+        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;
+        }
+    }
 }
 


ossp-pkg/lmtp2nntp/lmtp2nntp_dotconf.c 1.2 -> 1.3



ossp-pkg/lmtp2nntp/lmtp2nntp_dotconf.h 1.2 -> 1.3


CVSTrac 2.0.1