OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/lmtp2nntp_config.c versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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;
+        }
+    }
 }
 

CVSTrac 2.0.1