logo       

[CVS] Module ircu2.10: Change committed: msg#00014

Subject: [CVS] Module ircu2.10: Change committed
Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2006-06-27 11:29:17 UTC

Modified files:
     ircd/s_conf.c ircd/ircd_parser.y ircd/ircd_lexer.l
     doc/example.conf ChangeLog

Log message:

Implement limited configuration file inclusion.

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.780 ircu2.10/ChangeLog:1.781
--- ircu2.10/ChangeLog:1.780    Mon Jun 26 21:46:10 2006
+++ ircu2.10/ChangeLog  Tue Jun 27 04:29:06 2006
@@ -1,5 +1,27 @@
 2006-06-27  Michael Poole <mdpoole@xxxxxxxxxxx>
 
+       * doc/example.conf: Demonstrate the new inclusion syntax.
+
+       * ircd/ircd_lexer.l (init_lexer): Return a success indicator.
+       (lexer_include): New function.
+       (<<EOF>>): New handler.
+       (CHANNEL): Remove unused terminal symbol.
+       (TIMEOUT): Likewise.
+       (FROM): Recognize new terminal symbol.
+       (INCLUDE): Likewise.
+       (LINESYNC): Likewise.
+
+       * ircd/ircd_parser.y (%token): Remove CHANNEL, TIMEOUT; add
+       INCLUDE, LINESYNC, FROM, TEOF.
+       (block): Add includeblock production.
+       (includeblock): New production with several child productions.
+
+       * ircd/s_conf.c (lineno): Use external yylineno instead.
+       (read_configuration_file): Check init_lexer() return value.
+       (yyerror): Use yylineno instead.
+
+2006-06-27  Michael Poole <mdpoole@xxxxxxxxxxx>
+
        * configure.ac: Make sure that $LEX is flex-compatible.
 
        * test.l: Helper file for this test.
Index: ircu2.10/doc/example.conf
diff -u ircu2.10/doc/example.conf:1.70 ircu2.10/doc/example.conf:1.71
--- ircu2.10/doc/example.conf:1.70      Mon Jun 26 17:11:17 2006
+++ ircu2.10/doc/example.conf   Tue Jun 27 04:29:06 2006
@@ -734,6 +734,33 @@
 #  program = "../path/to/iauth" "-n" "options go here";
 # };
 
+# [Include]
+# You can include certain kinds of configuration snippets from other
+# files.  The basic directive, which allows any kind of block or
+# recursive include, is:
+#
+#   Include "filename";
+#
+# You can limit the file to certain types of configuration blocks by
+# using the block name.  The following options, and ONLY the following
+# options, are supported:
+#
+#   Include class from "filename";
+#   Include client from "filename";
+#   Include jupe from "filename";
+#   Include kill from "filename";
+#   Include linesync from "filename";
+#   Include operator from "filename";
+#   Include quarantine from "filename";
+#   Include uworld from "filename";
+#
+# The linesync option allows UWorld, Jupe, Quarantine, and Kill blocks.
+# If the file includes other blocks, it causes a config syntax error at
+# the Include line.
+#
+# Include client from "clients.conf";
+# Include operator from "opers.conf";
+
 # [features]
 # IRC servers have a large number of options and features.  Most of these
 # are set at compile time through the use of #define's--see "make config"
Index: ircu2.10/ircd/ircd_lexer.l
diff -u ircu2.10/ircd/ircd_lexer.l:1.25 ircu2.10/ircd/ircd_lexer.l:1.26
--- ircu2.10/ircd/ircd_lexer.l:1.25     Mon Jun 26 21:46:10 2006
+++ ircu2.10/ircd/ircd_lexer.l  Tue Jun 27 04:29:06 2006
@@ -17,45 +17,53 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  *  USA.
- * $Id: ircd_lexer.l,v 1.25 2006/06/27 04:46:10 entrope Exp $
+ * $Id: ircd_lexer.l,v 1.26 2006/06/27 11:29:06 entrope Exp $
  */
 
 %option never-interactive case-insensitive warn nodefault nounput yylineno
 
 %{
 
-#ifndef YY_FATAL_ERROR
-# define YY_FATAL_ERROR(MSG) fprintf(stderr, MSG)
-#endif
-
-#ifndef YY_NEW_FILE
-# define YY_NEW_FILE
-#endif
-
 #include "config.h"
 #include "ircd_alloc.h"
 #include "ircd_string.h"
 #include "ircd_parser.h"
 
-void
+extern void yyerror(const char *pattern);
+
+int
 init_lexer(const char *configfile)
 {
   yyin = fopen(configfile, "r");
   if (yyin == NULL)
   {
-    YY_FATAL_ERROR("Could not open the configuration file.");
+    fprintf(stderr, "Could not open the configuration file.");
+    return 0;
+  }
+  return 1;
+}
+
+void
+lexer_include(const char *filename)
+{
+  yyin = fopen(filename, "r");
+  if (yyin == NULL)
+  {
+    yyerror("Unable to open included configuration file.");
+    return TEOF;
   }
-  YY_NEW_FILE;
+  yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
 }
 
 %}
 
 %%
 
-\"[^"\n]+[\"\n] {yytext[yyleng-1] = 0; DupString(yylval.text, yytext+1); 
return QSTRING;}
+\"[^"\n]+[\"\n]        {yytext[yyleng-1] = 0; DupString(yylval.text, 
yytext+1); return QSTRING;}
 [0-9]+         {yylval.num = strtoul(yytext, NULL, 10); return NUMBER;}
 [ \t\r\n]+     ;
 #.*            ;
+<<EOF>>                { yypop_buffer_state(); if (YY_CURRENT_BUFFER) return 
TEOF; else yyterminate(); }
 
 ADMIN          return ADMIN;
 ADMINISTRATOR  return ADMIN;
@@ -66,7 +74,6 @@
 B              return BYTES;
 BADCHAN                return TPRIV_BADCHAN;
 BYTES          return BYTES;
-CHANNEL                return CHANNEL;
 CHAN_LIMIT     return TPRIV_CHAN_LIMIT;
 CLASS          return CLASS;
 CLIENT         return CLIENT;
@@ -85,6 +92,7 @@
 FILE           return TFILE;
 FORCE_LOCAL_OPMODE     return TPRIV_FORCE_LOCAL_OPMODE;
 FORCE_OPMODE   return TPRIV_FORCE_OPMODE;
+FROM           return FROM;
 GB             return GBYTES;
 GBYTES         return GBYTES;
 GENERAL                return GENERAL;
@@ -95,6 +103,7 @@
 HOURS          return HOURS;
 HUB            return HUB;
 IAUTH          return IAUTH;
+INCLUDE                return INCLUDE;
 IP             return IP;
 JUPE           return JUPE;
 KB             return KBYTES;
@@ -102,6 +111,7 @@
 KILOBYTES      return KBYTES;
 KILL           return KILL;
 LEAF           return LEAF;
+LINESYNC       return LINESYNC;
 LIST_CHAN      return TPRIV_LIST_CHAN;
 LOCAL          return LOCAL;
 LOCAL_BADCHAN  return TPRIV_LOCAL_BADCHAN;
@@ -149,7 +159,6 @@
 SET            return TPRIV_SET;
 SHOW_ALL_INVIS return TPRIV_SHOW_ALL_INVIS;
 SHOW_INVIS     return TPRIV_SHOW_INVIS;
-TIMEOUT                return TIMEOUT;
 TB             return TBYTES;
 TBYTES         return TBYTES;
 TERABYTES      return TBYTES;
Index: ircu2.10/ircd/ircd_parser.y
diff -u ircu2.10/ircd/ircd_parser.y:1.63 ircu2.10/ircd/ircd_parser.y:1.64
--- ircu2.10/ircd/ircd_parser.y:1.63    Mon Jun 26 17:11:17 2006
+++ ircu2.10/ircd/ircd_parser.y Tue Jun 27 04:29:06 2006
@@ -17,7 +17,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  *  USA.
- * $Id: ircd_parser.y,v 1.63 2006/06/27 00:11:17 entrope Exp $
+ * $Id: ircd_parser.y,v 1.64 2006/06/27 11:29:06 entrope Exp $
  */
 %{
 
@@ -97,7 +97,6 @@
 %token CONTACT
 %token CONNECT
 %token CLASS
-%token CHANNEL
 %token PINGFREQ
 %token CONNECTFREQ
 %token MAXLINKS
@@ -152,10 +151,13 @@
 %token PREPEND
 %token USERMODE
 %token IAUTH
-%token TIMEOUT
 %token FAST
 %token AUTOCONNECT
 %token PROGRAM
+%token INCLUDE
+%token LINESYNC
+%token FROM
+%token TEOF
 /* and now a lot of privileges... */
 %token TPRIV_CHAN_LIMIT TPRIV_MODE_LCHAN TPRIV_DEOP_LCHAN TPRIV_WALK_LCHAN
 %token TPRIV_LOCAL_KILL TPRIV_REHASH TPRIV_RESTART TPRIV_DIE
@@ -183,7 +185,7 @@
 block: adminblock | generalblock | classblock | connectblock |
        uworldblock | operblock | portblock | jupeblock | clientblock |
        killblock | cruleblock | motdblock | featuresblock | quarantineblock |
-       pseudoblock | iauthblock | error ';';
+       pseudoblock | iauthblock | includeblock | error ';';
 
 /* The timespec, sizespec and expr was ripped straight from
  * ircd-hybrid-7. */
@@ -1018,3 +1020,46 @@
   while (stringno > 0)
     MyFree(stringlist[stringno--]);
 } stringlist ';';
+
+includeblock: INCLUDE QSTRING ';' { lexer_include($2); } blocks TEOF;
+
+/* These limitations are truly a pain, but making the allowed blocks a
+ * function of a list after the INCLUDE means context dependency and
+ * making a build-time list of combinations, each one either a token
+ * emitted by the lexer (2**N token types, one state each) or a list
+ * of token permutations (O(N!) states) -- neither of which is a happy
+ * place for the generated parser.
+ */
+
+includeblock: INCLUDE LINESYNC FROM QSTRING ';' { lexer_include($4); } 
linesyncblocks2 TEOF;
+linesyncblocks2: linesyncblocks | error;
+linesyncblocks: linesyncblocks linesyncblock | ;
+linesyncblock: uworldblock | jupeblock | quarantineblock | killblock;
+
+includeblock: INCLUDE CLASS FROM QSTRING ';' { lexer_include($4); } 
classblocks2 TEOF;
+classblocks2: classblocks | error;
+classblocks: classblocks classblock | ;
+
+includeblock: INCLUDE UWORLD FROM QSTRING ';' { lexer_include($4); } 
uworldblocks2 TEOF;
+uworldblocks2: uworldblocks | error;
+uworldblocks: uworldblocks uworldblock | ;
+
+includeblock: INCLUDE OPER FROM QSTRING ';' { lexer_include($4); } operblocks2 
TEOF;
+operblocks2: operblocks | error;
+operblocks: operblocks operblock | ;
+
+includeblock: INCLUDE JUPE FROM QSTRING ';' { lexer_include($4); } jupeblocks2 
TEOF;
+jupeblocks2: jupeblocks | error;
+jupeblocks: jupeblocks jupeblock | ;
+
+includeblock: INCLUDE CLIENT FROM QSTRING ';' { lexer_include($4); } 
clientblocks2 TEOF;
+clientblocks2: clientblocks | error;
+clientblocks: clientblocks clientblock | ;
+
+includeblock: INCLUDE KILL FROM QSTRING ';' { lexer_include($4); } killblocks2 
TEOF;
+killblocks2: killblocks | error;
+killblocks: killblocks killblock | ;
+
+includeblock: INCLUDE QUARANTINE FROM QSTRING ';' { lexer_include($4); } 
quarantineblocks2 TEOF;
+quarantineblocks2: quarantineblocks | error;
+quarantineblocks: quarantineblocks quarantineblock | ;
Index: ircu2.10/ircd/s_conf.c
diff -u ircu2.10/ircd/s_conf.c:1.88 ircu2.10/ircd/s_conf.c:1.89
--- ircu2.10/ircd/s_conf.c:1.88 Mon Jun 26 21:46:10 2006
+++ ircu2.10/ircd/s_conf.c      Tue Jun 27 04:29:05 2006
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief ircd configuration file driver
- * @version $Id: s_conf.c,v 1.88 2006/06/27 04:46:10 entrope Exp $
+ * @version $Id: s_conf.c,v 1.89 2006/06/27 11:29:05 entrope Exp $
  */
 #include "config.h"
 
@@ -75,7 +75,7 @@
 struct qline     *GlobalQuarantineList;
 
 /** Current line number in scanner input. */
-int lineno;
+extern int yylineno;
 
 /** Configuration information for #me. */
 struct LocalConf   localConf;
@@ -825,7 +825,7 @@
 static int conf_already_read;
 extern FILE *yyin;
 extern void yyparse(void);
-extern void init_lexer(const char *configfile);
+extern int init_lexer(const char *configfile);
 
 /** Read configuration file.
  * @return Zero on failure, non-zero on success. */
@@ -833,7 +833,8 @@
 {
   conf_error = 0;
   feature_unmark(); /* unmark all features for resetting later */
-  init_lexer(configfile);
+  if (!init_lexer(configfile))
+    return 0;
   yyparse();
   fclose(yyin);
   yyin = NULL;
@@ -849,11 +850,11 @@
 yyerror(const char *msg)
 {
  sendto_opmask_butone(0, SNO_ALL, "Config file parse error line %d: %s",
-                      lineno, msg);
+                      yylineno, msg);
  log_write(LS_CONFIG, L_ERROR, 0, "Config file parse error line %d: %s",
-           lineno, msg);
+           yylineno, msg);
  if (!conf_already_read)
-   fprintf(stderr, "Config file parse error line %d: %s\n", lineno, msg);
+   fprintf(stderr, "Config file parse error line %d: %s\n", yylineno, msg);
  conf_error = 1;
 }
 
----------------------- End of diff -----------------------


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
linux.arklinux....    user-groups.lin...    kde.usability/2...    ietf.ipp/2002-0...    mail.spam.spamc...    os.netbsd.devel...    audio.cd-record...    text.unicode.de...    php.documentati...    games.fps.halfl...    window-managers...    suse.oracle.gen...    bug-tracking.gn...    video.dvdrip.us...    xfree86.cvs/200...    java.netbeans.m...    network.argus/2...    culture.sf.kill...    debian.ports.al...    freebsd.questio...    qplus.devel/200...    handhelds.palm....   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe