diff src/wflogs-config.h @ 2:400b1de6e1c6

allow multiple config contexts
author Carl Byington <carl@five-ten-sg.com>
date Fri, 17 May 2013 10:32:12 -0700
parents 0aa1171aebd2
children 37eace15ef87
line wrap: on
line diff
--- a/src/wflogs-config.h	Wed May 15 13:31:12 2013 -0700
+++ b/src/wflogs-config.h	Fri May 17 10:32:12 2013 -0700
@@ -1,6 +1,6 @@
 /*
 
-Copyright (c) 2007 Carl Byington - 510 Software Group, released under
+Copyright (c) 2013 Carl Byington - 510 Software Group, released under
 the GPL version 3 or any later version at your choice available at
 http://www.gnu.org/licenses/gpl-3.0.txt
 
@@ -20,10 +20,9 @@
 const int buflen = 1024;
 
 
-class CONFIG {
+class CONTEXT {
 public:
-    // the only mutable stuff once it has been loaded from the config file
-    int                 reference_count;    // protected by the global config_mutex
+    const char *        name;               // name of this context
     // input side
     int                 fd;                 // input fn syslog file
     struct stat         openfdstat;
@@ -32,10 +31,6 @@
     // output side
     int                 fdo;                // output tempin wflogs file
     time_t              open_time;          // time when fdo opened
-    // all the rest is constant after loading from the config file
-    int                 generation;
-    time_t              load_time;
-    string_set          config_files;
     TOKEN               *tokp;
     // our data
     int             period;     // in seconds
@@ -48,8 +43,8 @@
     const char *    pattern;    // regex to filter lines
     regex_t         re;         // internal regex to filter lines
 
-    CONFIG();
-    ~CONFIG();
+    CONTEXT(const char *nam);
+    ~CONTEXT();
     void    set_token(TOKEN &tok)       { tokp = &tok; };
     void    set_period(int p)           { period = p; };
     void    set_versions(int v)         { versions = v; };
@@ -61,15 +56,36 @@
     bool    failedo()                   { return (fdo == -1); };
     bool    failed()                    { return (fd == -1); };
     void    dump();
+    void    openo(bool msg);
     void    open(bool msg);
-    void    openo(bool msg);
+    bool    write(char *p);
     bool    read();
-    bool    write(char *p);
+    void    closeo();
+    void    close();
     void    process(char *p);
-    void    close();
-    void    closeo();
+    void    check_wflog();      // time to call it?
+    void    free_all();
+};
+typedef CONTEXT *               CONTEXTP;
+typedef list<CONTEXTP>          context_list;
+
+
+class CONFIG {
+public:
+    // the only mutable stuff once it has been loaded from the config file
+    int                 reference_count;    // protected by the global config_mutex
+    // all the rest is constant after loading from the config file
+    int                 generation;
+    time_t              load_time;
+    string_set          config_files;
+    context_list        contexts;
+
+    CONFIG();
+    ~CONFIG();
+    void    add_context(CONTEXTP con)  {contexts.push_back(con);} ;
+    void    dump();
+    bool    read();
     void    sleep(int duration, time_t &previous);
-    void    check_wflog();      // time to call it?
     void    free_all();
 };
 
@@ -77,11 +93,11 @@
 const char* register_string(string_set &s, const char *name);
 const char* register_string(const char *name);
 void        clear_strings();
-int         ip_address(const char *have);
 bool        load_conf(CONFIG &dc, const char *fn);
 void        token_init();
 
 
+extern const char *token_context;
 extern const char *token_file;
 extern const char *token_include;
 extern const char *token_lbrace;