mirror of
https://github.com/bol-van/zapret.git
synced 2024-11-15 02:58:34 +05:00
nfqws,tpws: move config parse to separate function
This commit is contained in:
parent
8b4b8c3fb0
commit
cc38472e32
46
nfq/nfqws.c
46
nfq/nfqws.c
@ -982,6 +982,30 @@ bool parse_tlspos(const char *s, enum tlspos *pos)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void config_from_file(const char *filename)
|
||||
{
|
||||
// config from a file
|
||||
char buf[MAX_CONFIG_FILE_SIZE];
|
||||
buf[0]='x'; // fake argv[0]
|
||||
buf[1]=' ';
|
||||
size_t bufsize=sizeof(buf)-3;
|
||||
if (!load_file(filename,buf+2,&bufsize))
|
||||
{
|
||||
DLOG_ERR("could not load config file '%s'\n",filename);
|
||||
exit_clean(1);
|
||||
}
|
||||
buf[bufsize+2]=0;
|
||||
// wordexp fails if it sees \t \n \r between args
|
||||
replace_char(buf,'\n',' ');
|
||||
replace_char(buf,'\r',' ');
|
||||
replace_char(buf,'\t',' ');
|
||||
if (wordexp(buf, ¶ms.wexp, WRDE_NOCMD))
|
||||
{
|
||||
DLOG_ERR("failed to split command line options from file '%s'\n",filename);
|
||||
exit_clean(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifdef __CYGWIN__
|
||||
@ -1048,27 +1072,7 @@ int main(int argc, char **argv)
|
||||
|
||||
if (argc>=2 && argv[1][0]=='@')
|
||||
{
|
||||
// config from a file
|
||||
|
||||
char buf[MAX_CONFIG_FILE_SIZE];
|
||||
buf[0]='x'; // fake argv[0]
|
||||
buf[1]=' ';
|
||||
size_t bufsize=sizeof(buf)-3;
|
||||
if (!load_file(argv[1]+1,buf+2,&bufsize))
|
||||
{
|
||||
DLOG_ERR("could not load config file '%s'\n",argv[1]+1);
|
||||
exit_clean(1);
|
||||
}
|
||||
buf[bufsize+2]=0;
|
||||
// wordexp fails if it sees \t \n \r between args
|
||||
replace_char(buf,'\n',' ');
|
||||
replace_char(buf,'\r',' ');
|
||||
replace_char(buf,'\t',' ');
|
||||
if (wordexp(buf, ¶ms.wexp, WRDE_NOCMD))
|
||||
{
|
||||
DLOG_ERR("failed to split command line options from file '%s'\n",argv[1]+1);
|
||||
exit_clean(1);
|
||||
}
|
||||
config_from_file(argv[1]+1);
|
||||
argv=params.wexp.we_wordv;
|
||||
argc=params.wexp.we_wordc;
|
||||
}
|
||||
|
45
tpws/tpws.c
45
tpws/tpws.c
@ -364,6 +364,29 @@ static bool parse_pf_list(char *opt, struct port_filters_head *pfl)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void config_from_file(const char *filename)
|
||||
{
|
||||
// config from a file
|
||||
char buf[MAX_CONFIG_FILE_SIZE];
|
||||
buf[0]='x'; // fake argv[0]
|
||||
buf[1]=' ';
|
||||
size_t bufsize=sizeof(buf)-3;
|
||||
if (!load_file(filename,buf+2,&bufsize))
|
||||
{
|
||||
DLOG_ERR("could not load config file '%s'\n",filename);
|
||||
exit_clean(1);
|
||||
}
|
||||
buf[bufsize+2]=0;
|
||||
// wordexp fails if it sees \t \n \r between args
|
||||
replace_char(buf,'\n',' ');
|
||||
replace_char(buf,'\r',' ');
|
||||
replace_char(buf,'\t',' ');
|
||||
if (wordexp(buf, ¶ms.wexp, WRDE_NOCMD))
|
||||
{
|
||||
DLOG_ERR("failed to split command line options from file '%s'\n",filename);
|
||||
exit_clean(1);
|
||||
}
|
||||
}
|
||||
|
||||
void parse_params(int argc, char *argv[])
|
||||
{
|
||||
@ -405,27 +428,7 @@ void parse_params(int argc, char *argv[])
|
||||
|
||||
if (argc>=2 && argv[1][0]=='@')
|
||||
{
|
||||
// config from a file
|
||||
|
||||
char buf[MAX_CONFIG_FILE_SIZE];
|
||||
buf[0]='x'; // fake argv[0]
|
||||
buf[1]=' ';
|
||||
size_t bufsize=sizeof(buf)-3;
|
||||
if (!load_file(argv[1]+1,buf+2,&bufsize))
|
||||
{
|
||||
DLOG_ERR("could not load config file '%s'\n",argv[1]+1);
|
||||
exit_clean(1);
|
||||
}
|
||||
buf[bufsize+2]=0;
|
||||
// wordexp fails if it sees \t \n \r between args
|
||||
replace_char(buf,'\n',' ');
|
||||
replace_char(buf,'\r',' ');
|
||||
replace_char(buf,'\t',' ');
|
||||
if (wordexp(buf, ¶ms.wexp, WRDE_NOCMD))
|
||||
{
|
||||
DLOG_ERR("failed to split command line options from file '%s'\n",argv[1]+1);
|
||||
exit_clean(1);
|
||||
}
|
||||
config_from_file(argv[1]+1);
|
||||
argv=params.wexp.we_wordv;
|
||||
argc=params.wexp.we_wordc;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user