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
80d20364
Commit
80d20364
authored
Mar 12, 2015
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify to use only one VSS_resolver() call and one call-back.
parent
8ac48328
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
40 deletions
+30
-40
vcc_utils.c
lib/libvcc/vcc_utils.c
+30
-40
No files found.
lib/libvcc/vcc_utils.c
View file @
80d20364
...
...
@@ -146,6 +146,9 @@ struct rss {
struct
suckaddr
*
vsa4
;
struct
suckaddr
*
vsa6
;
struct
vsb
*
vsb
;
int
retval
;
int
wrong
;
};
static
int
__match_proto__
(
vss_resolved_f
)
...
...
@@ -153,40 +156,33 @@ rs_callback(void *priv, const struct suckaddr *vsa)
{
struct
rss
*
rss
;
int
v
;
char
a
[
VTCP_ADDRBUFSIZE
];
char
p
[
VTCP_PORTBUFSIZE
];
CAST_OBJ_NOTNULL
(
rss
,
priv
,
RSS_MAGIC
);
assert
(
VSA_Sane
(
vsa
));
v
=
VSA_Get_Proto
(
vsa
);
VTCP_name
(
vsa
,
a
,
sizeof
a
,
p
,
sizeof
p
);
VSB_printf
(
rss
->
vsb
,
"
\t
%s:%s
\n
"
,
a
,
p
);
if
(
v
==
AF_INET
)
{
if
(
rss
->
vsa4
==
NULL
)
rss
->
vsa4
=
VSA_Clone
(
vsa
);
else
if
(
VSA_Compare
(
vsa
,
rss
->
vsa4
))
return
(
-
2
);
rss
->
wrong
++
;
rss
->
retval
++
;
}
else
if
(
v
==
AF_INET6
)
{
if
(
rss
->
vsa6
==
NULL
)
rss
->
vsa6
=
VSA_Clone
(
vsa
);
else
if
(
VSA_Compare
(
vsa
,
rss
->
vsa6
))
return
(
-
2
);
rss
->
wrong
++
;
rss
->
retval
++
;
}
else
{
WRONG
(
"Wrong protocol"
);
}
return
(
0
);
}
static
int
__match_proto__
(
vss_resolved_f
)
rs_callback2
(
void
*
priv
,
const
struct
suckaddr
*
vsa
)
{
struct
vcc
*
tl
;
char
a
[
VTCP_ADDRBUFSIZE
];
char
p
[
VTCP_PORTBUFSIZE
];
CAST_OBJ_NOTNULL
(
tl
,
priv
,
VCC_MAGIC
);
VTCP_name
(
vsa
,
a
,
sizeof
a
,
p
,
sizeof
p
);
VSB_printf
(
tl
->
sb
,
"
\t
%s:%s
\n
"
,
a
,
p
);
return
(
0
);
}
void
Resolve_Sockaddr
(
struct
vcc
*
tl
,
const
char
*
host
,
...
...
@@ -200,7 +196,7 @@ Resolve_Sockaddr(struct vcc *tl,
const
struct
token
*
t_err
,
const
char
*
errid
)
{
int
error
,
retval
=
0
;
int
error
;
struct
rss
*
rss
;
const
char
*
err
;
...
...
@@ -211,8 +207,11 @@ Resolve_Sockaddr(struct vcc *tl,
ALLOC_OBJ
(
rss
,
RSS_MAGIC
);
AN
(
rss
);
rss
->
vsb
=
VSB_new_auto
();
AN
(
rss
->
vsb
);
error
=
VSS_resolver
(
host
,
def_port
,
rs_callback
,
rss
,
&
err
);
AZ
(
VSB_finish
(
rss
->
vsb
));
if
(
err
!=
NULL
)
{
VSB_printf
(
tl
->
sb
,
"%s '%.*s' could not be resolved to an IP address:
\n
"
...
...
@@ -222,46 +221,37 @@ Resolve_Sockaddr(struct vcc *tl,
vcc_ErrWhere
(
tl
,
t_err
);
free
(
rss
->
vsa4
);
free
(
rss
->
vsa6
);
VSB_delete
(
rss
->
vsb
);
FREE_OBJ
(
rss
);
return
;
}
AZ
(
error
);
if
(
rss
->
vsa4
!=
NULL
)
{
vcc_suckaddr
(
tl
,
host
,
rss
->
vsa4
,
ipv4
,
ipv4_ascii
,
p_ascii
);
free
(
rss
->
vsa4
);
retval
++
;
}
if
(
rss
->
vsa6
!=
NULL
)
{
vcc_suckaddr
(
tl
,
host
,
rss
->
vsa6
,
ipv6
,
ipv6_ascii
,
p_ascii
);
free
(
rss
->
vsa6
);
retval
++
;
}
FREE_OBJ
(
rss
);
if
(
error
==
-
2
||
retval
>
maxips
)
{
if
(
rss
->
retval
==
0
)
{
VSB_printf
(
tl
->
sb
,
"%s '%.*s': resolves to "
"neither IPv4 nor IPv6 addresses.
\n
"
,
errid
,
PF
(
t_err
)
);
vcc_ErrWhere
(
tl
,
t_err
);
}
if
(
rss
->
wrong
||
rss
->
retval
>
maxips
)
{
VSB_printf
(
tl
->
sb
,
"%s %.*s: resolves to too many addresses.
\n
"
"Only one IPv4 %s IPv6 are allowed.
\n
"
"Please specify which exact address "
"you want to use, we found all of these:
\n
"
,
"you want to use, we found all of these:
\n
%s
"
,
errid
,
PF
(
t_err
),
maxips
>
1
?
"and one"
:
"or"
);
(
void
)
VSS_resolver
(
host
,
def_port
,
rs_callback2
,
tl
,
&
err
);
if
(
err
!=
NULL
)
{
VSB_printf
(
tl
->
sb
,
"%s '%.*s' could not be resolved to an"
" IP address:
\n
"
"
\t
%s
\n
"
"(Sorry if that error message is gibberish.)
\n
"
,
errid
,
PF
(
t_err
),
err
);
}
vcc_ErrWhere
(
tl
,
t_err
);
return
;
}
AZ
(
error
);
if
(
retval
==
0
)
{
VSB_printf
(
tl
->
sb
,
"%s '%.*s': resolves to "
"neither IPv4 nor IPv6 addresses.
\n
"
,
errid
,
PF
(
t_err
)
);
maxips
>
1
?
"and one"
:
"or"
,
VSB_data
(
rss
->
vsb
));
vcc_ErrWhere
(
tl
,
t_err
);
}
VSB_delete
(
rss
->
vsb
);
FREE_OBJ
(
rss
);
}
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