[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(usagi-users 03942) UMIP: add support to "include" in configuration file
- To: usagi-users@xxxxxxxxxxxxxx
- Subject: (usagi-users 03942) UMIP: add support to "include" in configuration file
- From: Sebastien Decugis <sdecugis@xxxxxxxxxxxxxxxx>
- Date: Fri, 21 Sep 2007 19:36:43 +0900
- Reply-to: usagi-users@xxxxxxxxxxxxxx
- Resent-date: Fri, 21 Sep 2007 23:30:48 +0900
- Resent-from: nakam@xxxxxxxxxxxxxx
- Resent-message-id: <200709212330.FMLAAB32292.usagi-users@linux-ipv6.org>
- Resent-to: usagi-users@xxxxxxxxxxxxxx (moderated)
- User-agent: Thunderbird 2.0.0.6 (Windows/20070728)
Hello,
The attached patch for umip-0.4 adds support for "include" keyword in
the mip6d.conf configuration file, in the form:
include "/path/to/some/other/file"
The wildcards are also supported, which allows for example:
include "/etc/mip6d.d/*.conf"
Please let me know if you have any question or comment about this patch.
Sebastien.
--
Sebastien Decugis
http://www.nautilus6.org
diff -Nur mipv6-daemon-umip-0.4-NEPL+DR/man/mip6d.conf.tmpl mipv6-daemon-umip-0.4-NEPL+DR+Nestconf/man/mip6d.conf.tmpl
--- mipv6-daemon-umip-0.4-NEPL+DR/man/mip6d.conf.tmpl 2007-09-19 11:26:54.000000000 +0900
+++ mipv6-daemon-umip-0.4-NEPL+DR+Nestconf/man/mip6d.conf.tmpl 2007-09-21 19:20:39.000000000 +0900
@@ -20,6 +20,14 @@
The file contains the following common definitions:
.TP
+.BR "include " """<pattern>"""
+
+Includes content from other files. Wildcards are supported.
+
+Example: include "/etc/mip6d.conf.d/*.conf"
+
+
+.TP
.BR "NodeConfig " "CN | HA | MN" ";"
Indicates if the daemon should run in Correspondent Node, Home Agent or
diff -Nur mipv6-daemon-umip-0.4-NEPL+DR/src/scan.l mipv6-daemon-umip-0.4-NEPL+DR+Nestconf/src/scan.l
--- mipv6-daemon-umip-0.4-NEPL+DR/src/scan.l 2007-09-19 11:20:20.000000000 +0900
+++ mipv6-daemon-umip-0.4-NEPL+DR+Nestconf/src/scan.l 2007-09-21 18:49:52.000000000 +0900
@@ -33,6 +33,8 @@
%{
#include <arpa/inet.h>
+#include <glob.h>
+#include <string.h>
#include "gram.h"
#define YY_NO_UNPUT 1
@@ -42,6 +44,22 @@
static int yywrap(void) { return 1; }
void yyerror(char *s);
+#define MAX_NESTED_CONF_FILES 5
+
+struct nested_conffiles_t{
+ YY_BUFFER_STATE parent_level_state;
+ glob_t filelist;
+ int current_file;
+} nested_conffiles[MAX_NESTED_CONF_FILES];
+
+int current_nested_level = 0;
+
+int globerrfct(const char *epath, int eerrno)
+{
+ fprintf(stderr, "Failed to scan %s: %s\n", epath, strerror(eerrno));
+ return 1;
+}
+
%}
%option nounput
@@ -52,6 +70,8 @@
%option noyyget_leng
%option noyyget_text
+%x in_include
+
ws [ \t]+
comment #.*
nl \n
@@ -68,6 +88,112 @@
false (disabled|deny|block|false)
%%
+include BEGIN(in_include);
+<in_include>{
+{ws} ;/* skip whitespaces */
+{qstring} { /* Name of the file to include. This is directly sent to glob. */
+ int globerror=0;
+ char * buf = strdup(yytext+1);
+ if (buf[yyleng-2] != '"')
+ {
+ fprintf(stderr, "Unterminated string: %s\n", yytext);
+ return INV_TOKEN;
+ }
+ buf[yyleng-2] = '\0';
+
+ if (current_nested_level >= MAX_NESTED_CONF_FILES)
+ {
+ fprintf(stderr, "Too many recursion levels in configuration files includes\n");
+ exit(1);
+ }
+
+ /* glob the include */
+ globerror = glob(buf, GLOB_ERR, globerrfct, &nested_conffiles[current_nested_level].filelist);
+
+ if (globerror == GLOB_NOSPACE)
+ {
+ fprintf(stderr, "Not enough memory to parse include directive.\n");
+ return INV_TOKEN;
+ }
+ if (globerror == GLOB_ABORTED)
+ {
+ fprintf(stderr, "An error was encountered in include directive.\n");
+ return INV_TOKEN;
+ }
+ if (globerror == GLOB_NOMATCH)
+ {
+ globfree(&nested_conffiles[current_nested_level].filelist);
+ goto nomatch;
+ }
+ if (globerror)
+ {
+ fprintf(stderr, "Unexpected error in glob (%d).\n", globerror);
+ return INV_TOKEN;
+ }
+
+ /* We have a list of files to include. */
+
+ /* save the current buffer for returning when this include has been parsed */
+ nested_conffiles[current_nested_level].parent_level_state = YY_CURRENT_BUFFER;
+
+ /* Start with the first match */
+ nested_conffiles[current_nested_level].current_file = 0;
+
+ yyin = fopen( nested_conffiles[current_nested_level].filelist.gl_pathv[0], "r" );
+
+ if ( ! yyin )
+ {
+ perror(nested_conffiles[current_nested_level].filelist.gl_pathv[0]);
+ return INV_TOKEN;
+ }
+
+ yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ));
+
+ /* In case of recursive includes */
+ current_nested_level++;
+
+nomatch:
+ BEGIN(INITIAL);
+ }
+}
+<<EOF>> {
+ if (current_nested_level == 0)
+ {
+ /* We are at the end of parsing */
+ yyterminate();
+ }
+
+ /* Otherwise we are doing an include statement */
+ --current_nested_level;
+ yy_delete_buffer(YY_CURRENT_BUFFER);
+
+ /* Go to next file, if any */
+ nested_conffiles[current_nested_level].current_file++;
+ if ( nested_conffiles[current_nested_level].filelist.gl_pathv[nested_conffiles[current_nested_level].current_file] == NULL )
+ {
+ /* We have finished with this list of includes */
+ globfree(&nested_conffiles[current_nested_level].filelist);
+ yy_switch_to_buffer(nested_conffiles[current_nested_level].parent_level_state);
+ }
+ else
+ {
+ /* Proceed to next included file */
+ yyin = fopen( nested_conffiles[current_nested_level].filelist.gl_pathv[nested_conffiles[current_nested_level].current_file], "r" );
+
+ if ( ! yyin )
+ {
+ perror(nested_conffiles[current_nested_level].filelist.gl_pathv[nested_conffiles[current_nested_level].current_file]);
+ return INV_TOKEN;
+ }
+
+ yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ));
+
+ /* In case of recursive includes */
+ current_nested_level++;
+ }
+
+ }
+
{ws} ;
{comment} ;
{nl} { lineno++; }