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
a200cd24
Commit
a200cd24
authored
Aug 06, 2013
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the sockaddr emitting function to vcc_utils.c (ne: vcc_string.c)
where the rest of the compiler can get at it.
parent
ffc4166d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
45 deletions
+54
-45
Makefile.am
lib/libvcl/Makefile.am
+1
-1
vcc_backend.c
lib/libvcl/vcc_backend.c
+4
-40
vcc_compile.h
lib/libvcl/vcc_compile.h
+2
-1
vcc_expr.c
lib/libvcl/vcc_expr.c
+2
-2
vcc_utils.c
lib/libvcl/vcc_utils.c
+45
-1
No files found.
lib/libvcl/Makefile.am
View file @
a200cd24
...
...
@@ -22,7 +22,7 @@ libvcl_la_SOURCES = \
vcc_fixed_token.c
\
vcc_obj.c
\
vcc_storage.c
\
vcc_
string
.c
\
vcc_
utils
.c
\
vcc_symb.c
\
vcc_token.c
\
vcc_var.c
\
...
...
lib/libvcl/vcc_backend.c
View file @
a200cd24
...
...
@@ -61,7 +61,6 @@
#include "vcc_compile.h"
#include "vss.h"
#include "vsa.h"
struct
host
{
VTAILQ_ENTRY
(
host
)
list
;
...
...
@@ -69,42 +68,6 @@ struct host {
char
*
vgcname
;
};
/*
* The IPv6 crew royally screwed up the entire idea behind
* struct sockaddr, and combined with various other incomptency
* in the OS business, that means that there is no sane or even
* remotely portable way to initialize a sockaddr at compile time.
*
* In our case it is slightly more tricky than that, because we don't
* even want to #include the struct sockaddr* definitions.
*
* Instead we make sure the sockaddr is sane (for our values of sane)
* and dump it in binary, using a 64 bit integertype, hoping that this
* will ensure good enough alignment.
*/
static
int
emit_sockaddr
(
struct
vcc
*
tl
,
const
void
*
sa
,
unsigned
sal
)
{
unsigned
n
=
(
sal
+
7
)
/
8
,
len
;
uint64_t
b
[
n
];
assert
(
VSA_Sane
(
sa
));
AN
(
sa
);
AN
(
sal
);
assert
(
sal
<
256
);
assert
(
sizeof
(
unsigned
long
long
)
==
8
);
Fh
(
tl
,
0
,
"
\n
static const unsigned long long"
);
Fh
(
tl
,
0
,
" sockaddr_%u[%d] = {
\n
"
,
tl
->
unique
,
n
);
memcpy
(
b
,
sa
,
sal
);
for
(
len
=
0
;
len
<
n
;
len
++
)
{
Fh
(
tl
,
0
,
"%s 0x%016jx"
,
len
?
",
\n
"
:
""
,
(
uintmax_t
)
b
[
len
]);
}
Fh
(
tl
,
0
,
"
\n
};
\n
"
);
return
(
tl
->
unique
++
);
}
/*--------------------------------------------------------------------
* Struct sockaddr is not really designed to be a compile time
...
...
@@ -124,9 +87,10 @@ Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const char *port)
{
struct
foo_proto
protos
[
3
],
*
pp
;
struct
addrinfo
*
res
,
*
res0
,
*
res1
,
hint
;
int
error
,
retval
,
x
;
int
error
,
retval
;
char
hbuf
[
NI_MAXHOST
];
char
*
hop
,
*
pop
;
const
char
*
sa
;
AN
(
t_host
->
dec
);
...
...
@@ -204,8 +168,8 @@ Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const char *port)
pp
->
l
=
res
->
ai_addrlen
;
memcpy
(
&
pp
->
sa
,
res
->
ai_addr
,
pp
->
l
);
x
=
emit
_sockaddr
(
tl
,
res
->
ai_addr
,
res
->
ai_addrlen
);
Fb
(
tl
,
0
,
"
\t
.%s_sockaddr =
sockaddr_%u,
\n
"
,
pp
->
name
,
x
);
sa
=
vcc
_sockaddr
(
tl
,
res
->
ai_addr
,
res
->
ai_addrlen
);
Fb
(
tl
,
0
,
"
\t
.%s_sockaddr =
%s,
\n
"
,
pp
->
name
,
sa
);
error
=
getnameinfo
(
res
->
ai_addr
,
res
->
ai_addrlen
,
hbuf
,
sizeof
hbuf
,
NULL
,
0
,
NI_NUMERICHOST
);
...
...
lib/libvcl/vcc_compile.h
View file @
a200cd24
...
...
@@ -286,7 +286,8 @@ void vcc_Parse(struct vcc *tl);
sym_wildcard_t
vcc_Stv_Wildcard
;
/* vcc_string.c */
char
*
vcc_regexp
(
struct
vcc
*
tl
);
const
char
*
vcc_regexp
(
struct
vcc
*
tl
);
const
char
*
vcc_sockaddr
(
struct
vcc
*
tl
,
const
void
*
sa
,
unsigned
sal
);
/* vcc_symb.c */
struct
symbol
*
VCC_AddSymbolStr
(
struct
vcc
*
tl
,
const
char
*
name
,
enum
symkind
);
...
...
lib/libvcl/vcc_expr.c
View file @
a200cd24
...
...
@@ -441,7 +441,7 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym)
{
struct
expr
*
e2
;
int
all
=
sym
->
eval_priv
==
NULL
?
0
:
1
;
char
*
p
;
c
onst
c
har
*
p
;
char
buf
[
128
];
vcc_delete_expr
(
*
e
);
...
...
@@ -963,7 +963,7 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, enum var_type fmt)
struct
expr
*
e2
;
const
struct
cmps
*
cp
;
char
buf
[
256
];
char
*
re
;
c
onst
c
har
*
re
;
const
char
*
not
;
struct
token
*
tk
;
...
...
lib/libvcl/vcc_
string
.c
→
lib/libvcl/vcc_
utils
.c
View file @
a200cd24
...
...
@@ -31,15 +31,17 @@
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include "vcc_compile.h"
#include "vre.h"
#include "vrt.h"
#include "vsa.h"
/*--------------------------------------------------------------------*/
char
*
c
onst
c
har
*
vcc_regexp
(
struct
vcc
*
tl
)
{
char
buf
[
BUFSIZ
],
*
p
;
...
...
@@ -70,3 +72,45 @@ vcc_regexp(struct vcc *tl)
Ff
(
tl
,
0
,
"
\t
VRT_re_fini(%s);
\n
"
,
buf
);
return
(
p
);
}
/*
* The IPv6 crew royally screwed up the entire idea behind
* struct sockaddr, and combined with various other incomptency
* in the OS business, that means that there is no sane or even
* remotely portable way to initialize a sockaddr at compile time.
*
* In our case it is slightly more tricky than that, because we don't
* even want to #include the struct sockaddr* definitions.
*
* Instead we make sure the sockaddr is sane (for our values of sane)
* and dump it in binary, using a 64 bit integertype, hoping that this
* will ensure good enough alignment.
*/
const
char
*
vcc_sockaddr
(
struct
vcc
*
tl
,
const
void
*
sa
,
unsigned
sal
)
{
unsigned
n
=
(
sal
+
7
)
/
8
,
len
;
uint64_t
b
[
n
];
char
*
p
;
assert
(
VSA_Sane
(
sa
));
AN
(
sa
);
AN
(
sal
);
assert
(
sal
<
256
);
assert
(
sizeof
(
unsigned
long
long
)
==
8
);
p
=
TlAlloc
(
tl
,
20
);
sprintf
(
p
,
"sockaddr_%u"
,
tl
->
unique
++
);
Fh
(
tl
,
0
,
"
\n
static const unsigned long long"
);
Fh
(
tl
,
0
,
" %s[%d] = {
\n
"
,
p
,
n
);
memcpy
(
b
,
sa
,
sal
);
for
(
len
=
0
;
len
<
n
;
len
++
)
{
Fh
(
tl
,
0
,
"%s 0x%016jx"
,
len
?
",
\n
"
:
""
,
(
uintmax_t
)
b
[
len
]);
}
Fh
(
tl
,
0
,
"
\n
};
\n
"
);
return
(
p
);
}
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