There is already support for loadpath in the sr core.
Jan.
On 03-04 12:20, Henning Westerholt wrote:
- add support for 'mpath' argument, to avoid
specifying a common module path
over and over again
- small adaption because of different structure in the sr cfg parser
---
cfg.lex | 2 ++
cfg.y | 28 ++++++++++++++++++++++++++--
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/cfg.lex b/cfg.lex
index 9f42697..229c2b2 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -394,6 +394,7 @@ SERVER_ID "server_id"
CFG_DESCRIPTION "description"|"descr"|"desc"
+MPATH mpath
LOADMODULE loadmodule
LOADPATH loadpath
MODPARAM modparam
@@ -741,6 +742,7 @@ EAT_ABLE [\ \t\b\r]
return MAX_WLOOPS; }
<INITIAL>{SERVER_ID} { count(); yylval.strval=yytext; return SERVER_ID;}
<INITIAL>{CFG_DESCRIPTION} { count(); yylval.strval=yytext; return
CFG_DESCRIPTION; }
+<INITIAL>{MPATH} { count(); yylval.strval=yytext; return MPATH; }
<INITIAL>{LOADMODULE} { count(); yylval.strval=yytext; return LOADMODULE; }
<INITIAL>{LOADPATH} { count(); yylval.strval=yytext; return LOADPATH; }
<INITIAL>{MODPARAM} { count(); yylval.strval=yytext; return MODPARAM; }
diff --git a/cfg.y b/cfg.y
index de7643d..44074ab 100644
--- a/cfg.y
+++ b/cfg.y
@@ -223,6 +223,9 @@ static struct case_stms* mk_case_stm(struct rval_expr* ct,
int is_re,
static int case_check_type(struct case_stms* stms);
static int case_check_default(struct case_stms* stms);
+static char *mpath=NULL;
+static char mpath_buf[256];
+static int mpath_len = 0;
%}
@@ -376,6 +379,7 @@ static int case_check_default(struct case_stms* stms);
%token SERVER_SIGNATURE
%token REPLY_TO_VIA
%token LOADMODULE
+%token MPATH
%token LOADPATH
%token MODPARAM
%token MAXBUFFER
@@ -1346,6 +1350,16 @@ assign_stm:
| UDP_MTU_TRY_PROTO EQUAL error
{ yyerror("TCP, TLS, SCTP or UDP expected"); }
| cfg_var
+ | MPATH EQUAL STRING { mpath=$3; strcpy(mpath_buf, $3);
+ mpath_len=strlen($3);
+ if(mpath_buf[mpath_len-1]!='/') {
+ mpath_buf[mpath_len]='/';
+ mpath_len++;
+ mpath_buf[mpath_len]='\0';
+ }
+ }
+ | MPATH EQUAL error { yyerror("string value expected"); }
+
| error EQUAL { yyerror("unknown config variable"); }
;
cfg_var:
@@ -1373,10 +1387,20 @@ cfg_var:
;
module_stm:
LOADMODULE STRING {
- DBG("loading module %s\n", $2);
- if (load_module($2)!=0) {
+ if(*$2!='/' && mpath!=NULL && strlen($2)+mpath_len<255)
+ {
+ strcpy(mpath_buf+mpath_len, $2);
+ DBG("loading module %s\n", mpath_buf);
+ if (load_module(mpath_buf)!=0){
yyerror("failed to load module");
}
+ mpath_buf[mpath_len]='\0';
+ } else {
+ DBG("loading module %s\n", $2);
+ if (load_module($2)!=0){
+ yyerror("failed to load module");
+ }
+ }
}
| LOADMODULE error { yyerror("string expected"); }
| LOADPATH STRING {