Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
195929e4
Commit
195929e4
authored
Apr 13, 2021
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement `+glob` flag to `include` processing.
Reimplementation of #3193 according to consensus.
parent
1a02b474
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
37 deletions
+94
-37
vcc_source.c
lib/libvcc/vcc_source.c
+94
-37
No files found.
lib/libvcc/vcc_source.c
View file @
195929e4
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include "config.h"
#include "config.h"
#include <glob.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
...
@@ -99,41 +100,16 @@ vcc_file_source(const struct vcc *tl, const char *fn)
...
@@ -99,41 +100,16 @@ vcc_file_source(const struct vcc *tl, const char *fn)
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
static
struct
source
*
static
int
vcc_include_file
(
struct
vcc
*
tl
,
const
struct
source
*
src_sp
,
vcc_include_file
(
struct
vcc
*
tl
,
const
struct
source
*
src_sp
,
const
char
*
filename
,
const
struct
token
*
parent_token
)
const
char
*
filename
,
const
struct
token
*
parent_token
)
{
{
struct
source
*
sp
;
struct
source
*
sp
;
const
struct
source
*
sp1
;
const
struct
source
*
sp1
;
struct
vsb
*
vsb
;
const
char
*
p
;
if
(
filename
[
0
]
==
'.'
&&
filename
[
1
]
==
'/'
)
{
/*
* Nested include filenames, starting with "./" are
* resolved relative to the VCL file which contains
* the include directive.
*/
if
(
src_sp
->
name
[
0
]
!=
'/'
)
{
VSB_cat
(
tl
->
sb
,
"include
\"
./xxxxx
\"
; needs absolute "
"filename of including file.
\n
"
);
return
(
NULL
);
}
vsb
=
VSB_new_auto
();
AN
(
vsb
);
p
=
strrchr
(
src_sp
->
name
,
'/'
);
AN
(
p
);
VSB_bcat
(
vsb
,
src_sp
->
name
,
p
-
src_sp
->
name
);
VSB_cat
(
vsb
,
filename
+
1
);
AZ
(
VSB_finish
(
vsb
));
sp
=
vcc_file_source
(
tl
,
VSB_data
(
vsb
));
VSB_destroy
(
&
vsb
);
}
else
{
sp
=
vcc_file_source
(
tl
,
filename
);
sp
=
vcc_file_source
(
tl
,
filename
);
}
if
(
sp
==
NULL
)
if
(
sp
==
NULL
)
return
(
sp
);
return
(
-
1
);
for
(
sp1
=
src_sp
;
sp1
!=
NULL
;
sp1
=
sp1
->
parent
)
for
(
sp1
=
src_sp
;
sp1
!=
NULL
;
sp1
=
sp1
->
parent
)
if
(
!
strcmp
(
sp1
->
name
,
sp
->
name
))
if
(
!
strcmp
(
sp1
->
name
,
sp
->
name
))
...
@@ -142,24 +118,60 @@ vcc_include_file(struct vcc *tl, const struct source *src_sp,
...
@@ -142,24 +118,60 @@ vcc_include_file(struct vcc *tl, const struct source *src_sp,
VSB_printf
(
tl
->
sb
,
VSB_printf
(
tl
->
sb
,
"Recursive include of
\"
%s
\"\n\n
"
,
sp
->
name
);
"Recursive include of
\"
%s
\"\n\n
"
,
sp
->
name
);
vcc_destroy_source
(
&
sp
);
vcc_destroy_source
(
&
sp
);
return
(
NULL
);
return
(
-
1
);
}
}
sp
->
parent
=
src_sp
;
sp
->
parent
=
src_sp
;
VTAILQ_INSERT_TAIL
(
&
tl
->
sources
,
sp
,
list
);
VTAILQ_INSERT_TAIL
(
&
tl
->
sources
,
sp
,
list
);
sp
->
idx
=
tl
->
nsources
++
;
sp
->
idx
=
tl
->
nsources
++
;
sp
->
parent_tok
=
parent_token
;
sp
->
parent_tok
=
parent_token
;
vcc_lex_source
(
tl
,
sp
,
0
);
vcc_lex_source
(
tl
,
sp
,
0
);
return
(
sp
);
return
(
0
);
}
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
static
int
vcc_include_glob_file
(
struct
vcc
*
tl
,
const
struct
source
*
src_sp
,
const
char
*
filename
,
const
struct
token
*
parent_token
)
{
glob_t
g
[
1
];
int
rv
;
unsigned
u
;
memset
(
g
,
0
,
sizeof
g
);
rv
=
glob
(
filename
,
0
,
NULL
,
g
);
switch
(
rv
)
{
case
0
:
for
(
u
=
0
;
rv
==
0
&&
u
<
g
->
gl_pathc
;
u
++
)
{
rv
=
vcc_include_file
(
tl
,
src_sp
,
g
->
gl_pathv
[
u
],
parent_token
);
}
break
;
case
GLOB_NOMATCH
:
VSB_printf
(
tl
->
sb
,
"glob pattern matched no files.
\n
"
);
break
;
default:
VSB_printf
(
tl
->
sb
,
"glob(3) expansion failed (%d)
\n
"
,
rv
);
break
;
}
globfree
(
g
);
return
(
rv
);
}
/*--------------------------------------------------------------------
* NB: We cannot use vcc_ErrWhere2() on tokens which are no on the
* NB: tl->tokens list.
*/
void
void
vcc_lex_source
(
struct
vcc
*
tl
,
struct
source
*
src_sp
,
int
eoi
)
vcc_lex_source
(
struct
vcc
*
tl
,
struct
source
*
src_sp
,
int
eoi
)
{
{
struct
token
*
t
,
*
t1
;
struct
token
*
t
,
*
t1
;
struct
source
*
sp
;
int
i
,
glob_flag
=
0
;
const
struct
source
*
sp1
;
const
struct
source
*
sp1
;
struct
vsb
*
vsb
=
NULL
;
const
char
*
filename
;
const
char
*
p
;
vcc_Lexer
(
tl
,
src_sp
);
vcc_Lexer
(
tl
,
src_sp
);
if
(
tl
->
err
)
if
(
tl
->
err
)
...
@@ -174,27 +186,72 @@ vcc_lex_source(struct vcc *tl, struct source *src_sp, int eoi)
...
@@ -174,27 +186,72 @@ vcc_lex_source(struct vcc *tl, struct source *src_sp, int eoi)
}
}
t1
=
VTAILQ_NEXT
(
t
,
src_list
);
t1
=
VTAILQ_NEXT
(
t
,
src_list
);
AN
(
t1
);
/* There's always an EOI */
AN
(
t1
);
while
(
1
)
{
t
=
VTAILQ_NEXT
(
t1
,
src_list
);
AN
(
t
);
i
=
vcc_IsFlagRaw
(
tl
,
t1
,
t
);
if
(
i
<
0
)
break
;
if
(
vcc_IdIs
(
t
,
"glob"
))
{
glob_flag
=
i
;
}
else
{
VSB_cat
(
tl
->
sb
,
"Unknown include flag:
\n
"
);
vcc_ErrWhere
(
tl
,
t
);
return
;
}
t1
=
VTAILQ_NEXT
(
t
,
src_list
);
AN
(
t1
);
}
if
(
t1
->
tok
!=
CSTR
)
{
if
(
t1
->
tok
!=
CSTR
)
{
VSB_cat
(
tl
->
sb
,
VSB_cat
(
tl
->
sb
,
"include not followed by string constant.
\n
"
);
"include not followed by string constant.
\n
"
);
/* Not vcc_ErrWhere2(): tokens not on final list */
vcc_ErrWhere
(
tl
,
t1
);
vcc_ErrWhere
(
tl
,
t1
);
return
;
return
;
}
}
t
=
VTAILQ_NEXT
(
t1
,
src_list
);
t
=
VTAILQ_NEXT
(
t1
,
src_list
);
AN
(
t
);
/* There's always an EOI */
AN
(
t
);
if
(
t
->
tok
!=
';'
)
{
if
(
t
->
tok
!=
';'
)
{
VSB_cat
(
tl
->
sb
,
VSB_cat
(
tl
->
sb
,
"include <string> not followed by semicolon.
\n
"
);
"include <string> not followed by semicolon.
\n
"
);
/* Not vcc_ErrWhere2(): tokens not on final list */
vcc_ErrWhere
(
tl
,
t1
);
vcc_ErrWhere
(
tl
,
t1
);
return
;
return
;
}
}
sp
=
vcc_include_file
(
tl
,
src_sp
,
t1
->
dec
,
t1
);
filename
=
t1
->
dec
;
if
(
sp
==
NULL
)
{
if
(
filename
[
0
]
==
'.'
&&
filename
[
1
]
==
'/'
)
{
/*
* Nested include filenames, starting with "./" are
* resolved relative to the VCL file which contains
* the include directive.
*/
if
(
src_sp
->
name
[
0
]
!=
'/'
)
{
VSB_cat
(
tl
->
sb
,
"include
\"
./xxxxx
\"
; needs absolute "
"filename of including file.
\n
"
);
return
;
}
vsb
=
VSB_new_auto
();
AN
(
vsb
);
p
=
strrchr
(
src_sp
->
name
,
'/'
);
AN
(
p
);
VSB_bcat
(
vsb
,
src_sp
->
name
,
p
-
src_sp
->
name
);
VSB_cat
(
vsb
,
filename
+
1
);
AZ
(
VSB_finish
(
vsb
));
filename
=
VSB_data
(
vsb
);
}
if
(
glob_flag
)
i
=
vcc_include_glob_file
(
tl
,
src_sp
,
filename
,
t1
);
else
i
=
vcc_include_file
(
tl
,
src_sp
,
filename
,
t1
);
if
(
vsb
!=
NULL
)
VSB_destroy
(
&
vsb
);
if
(
i
)
{
vcc_ErrWhere
(
tl
,
t1
);
vcc_ErrWhere
(
tl
,
t1
);
for
(
sp1
=
src_sp
;
sp1
!=
NULL
;
sp1
=
sp1
->
parent
)
{
for
(
sp1
=
src_sp
;
sp1
!=
NULL
;
sp1
=
sp1
->
parent
)
{
if
(
sp1
->
parent_tok
==
NULL
)
if
(
sp1
->
parent_tok
==
NULL
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment