Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
44ee67ff
Commit
44ee67ff
authored
Mar 24, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: Refactor split_host_port
parent
144ae3af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
19 deletions
+18
-19
src/shrpx_config.cc
src/shrpx_config.cc
+18
-19
No files found.
src/shrpx_config.cc
View file @
44ee67ff
...
...
@@ -78,31 +78,30 @@ TicketKeys::~TicketKeys() {
namespace
{
int
split_host_port
(
char
*
host
,
size_t
hostlen
,
uint16_t
*
port_ptr
,
const
char
*
hostport
,
size_t
hostportlen
)
{
const
StringRef
&
hostport
,
const
char
*
opt
)
{
// host and port in |hostport| is separated by single ','.
const
char
*
p
=
strchr
(
hostport
,
','
);
if
(
!
p
)
{
LOG
(
ERROR
)
<<
"
Invalid host, port: "
<<
hostport
;
auto
sep
=
std
::
find
(
std
::
begin
(
hostport
),
std
::
end
(
hostport
)
,
','
);
if
(
sep
==
std
::
end
(
hostport
)
)
{
LOG
(
ERROR
)
<<
opt
<<
":
Invalid host, port: "
<<
hostport
;
return
-
1
;
}
size_t
len
=
p
-
hostport
;
size_t
len
=
sep
-
std
::
begin
(
hostport
)
;
if
(
hostlen
<
len
+
1
)
{
LOG
(
ERROR
)
<<
"
Hostname too long: "
<<
hostport
;
LOG
(
ERROR
)
<<
opt
<<
":
Hostname too long: "
<<
hostport
;
return
-
1
;
}
memcpy
(
host
,
hostport
,
len
);
std
::
copy
(
std
::
begin
(
hostport
),
sep
,
host
);
host
[
len
]
=
'\0'
;
errno
=
0
;
auto
portlen
=
hostportlen
-
len
-
1
;
auto
d
=
util
::
parse_uint
(
reinterpret_cast
<
const
uint8_t
*>
(
p
+
1
),
portlen
);
auto
portstr
=
StringRef
{
sep
+
1
,
std
::
end
(
hostport
)};
auto
d
=
util
::
parse_uint
(
portstr
);
if
(
1
<=
d
&&
d
<=
std
::
numeric_limits
<
uint16_t
>::
max
())
{
*
port_ptr
=
d
;
return
0
;
}
else
{
LOG
(
ERROR
)
<<
"Port is invalid: "
<<
std
::
string
(
p
+
1
,
portlen
);
return
-
1
;
}
LOG
(
ERROR
)
<<
opt
<<
": Port is invalid: "
<<
portstr
;
return
-
1
;
}
}
// namespace
...
...
@@ -1753,8 +1752,8 @@ int parse_config(const char *opt, const char *optarg,
addr
.
host
=
ImmutableString
(
path
,
addr_end
);
addr
.
host_unix
=
true
;
}
else
{
if
(
split_host_port
(
host
,
sizeof
(
host
),
&
port
,
src
.
c_str
(),
addr_end
-
std
::
begin
(
src
)
)
==
-
1
)
{
if
(
split_host_port
(
host
,
sizeof
(
host
),
&
port
,
StringRef
{
std
::
begin
(
src
),
addr_end
},
opt
)
==
-
1
)
{
return
-
1
;
}
...
...
@@ -1802,8 +1801,8 @@ int parse_config(const char *opt, const char *optarg,
return
0
;
}
if
(
split_host_port
(
host
,
sizeof
(
host
),
&
port
,
src
.
c_str
(),
addr_end
-
std
::
begin
(
src
)
)
==
-
1
)
{
if
(
split_host_port
(
host
,
sizeof
(
host
),
&
port
,
StringRef
{
std
::
begin
(
src
),
addr_end
},
opt
)
==
-
1
)
{
return
-
1
;
}
...
...
@@ -2451,8 +2450,8 @@ int parse_config(const char *opt, const char *optarg,
return
-
1
;
}
if
(
split_host_port
(
host
,
sizeof
(
host
),
&
port
,
src
.
c_str
(),
addr_end
-
std
::
begin
(
src
)
)
==
-
1
)
{
if
(
split_host_port
(
host
,
sizeof
(
host
),
&
port
,
StringRef
{
std
::
begin
(
src
),
addr_end
},
opt
)
==
-
1
)
{
return
-
1
;
}
...
...
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