<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255); text-align: left;" dir="auto">
<span style="font-family: sans-serif; font-size: 11pt;">I send my email with mobile phone client, and it is difficult to handle indent </span><br>
</div>
<div id="id-7dda3927-b5f7-4a3f-b215-15ee8790fbc4" class="ms-outlook-mobile-reference-message" dir="auto" style="text-align: left;">
<font size="2"><span style="font-size:11pt;">
<div class="PlainText" dir="auto" style="text-align: left;">spaces.. :(<br>
<br>
inet_pton() is better than my ugly code, and I have revised it:<br>
<br>
---<br>
<br>
.../demux/adaptive/http/ConnectionParams.cpp | 24 ++++++++++++++++++-<br>
.../demux/adaptive/http/ConnectionParams.hpp | 2 ++<br>
.../demux/adaptive/http/HTTPConnection.cpp | 14 +++++++++--<br>
3 files changed, 37 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/modules/demux/adaptive/http/ConnectionParams.cpp <br>
b/modules/demux/adaptive/http/ConnectionParams.cpp<br>
index 6e3f221b66..3833e3a5e1 100644<br>
--- a/modules/demux/adaptive/http/ConnectionParams.cpp<br>
+++ b/modules/demux/adaptive/http/ConnectionParams.cpp<br>
@@ -69,7 +69,10 @@ void ConnectionParams::setPath(const std::string &path_)<br>
os << scheme << "://";<br>
if(!hostname.empty())<br>
{<br>
- os << hostname;<br>
+ if (ipv6)<br>
+ os << '[' << hostname << ']';<br>
+ else<br>
+ os << hostname;<br>
if( (port != 80 && scheme != "http") ||<br>
(port != 443 && scheme != "https") )<br>
os << ":" << port;<br>
@@ -88,6 +91,22 @@ bool ConnectionParams::isLocal() const<br>
return scheme != "http" && scheme != "https";<br>
}<br>
<br>
+bool isIPv6() const;<br>
+{<br>
+ return ipv6;<br>
+}<br>
+<br>
+#ifdef _WIN32<br>
+#include <ws2tcpip.h><br>
+#else<br>
+#include <arpa/inet.h><br>
+#endif<br>
+static inline int is_ipv6_addr (const char * host)<br>
+{<br>
+ unsigned char buf[sizeof(struct in6_addr)];<br>
+ return inet_pton(AF_INET6, host, buf) == 1;<br>
+}<br>
+<br>
void ConnectionParams::parse()<br>
{<br>
vlc_url_t url_components;<br>
@@ -108,7 +127,10 @@ void ConnectionParams::parse()<br>
port = url_components.i_port ? url_components.i_port :<br>
((scheme == "https") ? 443 : 80);<br>
if(url_components.psz_host)<br>
+ {<br>
hostname = url_components.psz_host;<br>
+ ipv6 = is_ipv6_addr(url_components.psz_host);<br>
+ }<br>
<br>
vlc_UrlClean(&url_components);<br>
}<br>
diff --git a/modules/demux/adaptive/http/ConnectionParams.hpp <br>
b/modules/demux/adaptive/http/ConnectionParams.hpp<br>
index fb9f9d9af1..868bd97ac6 100644<br>
--- a/modules/demux/adaptive/http/ConnectionParams.hpp<br>
+++ b/modules/demux/adaptive/http/ConnectionParams.hpp<br>
@@ -62,6 +62,7 @@ namespace adaptive<br>
bool isLocal() const;<br>
void setPath(const std::string &);<br>
uint16_t getPort() const;<br>
+ bool isIPv6() const;<br>
<br>
private:<br>
void parse();<br>
@@ -70,6 +71,7 @@ namespace adaptive<br>
std::string hostname;<br>
std::string path;<br>
uint16_t port;<br>
+ bool ipv6;<br>
};<br>
}<br>
}<br>
diff --git a/modules/demux/adaptive/http/HTTPConnection.cpp <br>
b/modules/demux/adaptive/http/HTTPConnection.cpp<br>
index 36354c5b90..e10344012f 100644<br>
--- a/modules/demux/adaptive/http/HTTPConnection.cpp<br>
+++ b/modules/demux/adaptive/http/HTTPConnection.cpp<br>
@@ -432,11 +432,21 @@ std::string <br>
HTTPConnection::buildRequestHeader(const std::string &path) const<br>
if((params.getScheme() == "http" && params.getPort() != 80) ||<br>
(params.getScheme() == "https" && params.getPort() != 443))<br>
{<br>
- req << "Host: " << params.getHostname() << ":" << <br>
params.getPort() << "\r\n";<br>
+ req << "Host: ";<br>
+ if (params.isIPv6())<br>
+ req << '[' << params.getHostname() << ']';<br>
+ else<br>
+ req << params.getHostname();<br>
+ req << ":" << params.getPort() << "\r\n";<br>
}<br>
else<br>
{<br>
- req << "Host: " << params.getHostname() << "\r\n";<br>
+ req << "Host: ";<br>
+ if (params.isIPv6())<br>
+ req << '[' << params.getHostname() << ']';<br>
+ else<br>
+ req << params.getHostname();<br>
+ req << "\r\n";<br>
}<br>
if(authStorage)<br>
{<br>
-- <br>
2.17.1<br>
<br>
On 2020/12/20 ÏÂÎç4:13, R¨¦mi Denis-Courmont wrote:<br>
> Nihao,<br>
><br>
> Comments inline...<br>
><br>
> Le lauantaina 19. joulukuuta 2020, 11.53.48 EET Xie Zhigang a ¨¦crit :<br>
>> +bool isIPv6() const;<br>
>> +{<br>
>> + return ipv6;<br>
>> +}<br>
>> +<br>
>> +static int is_ipv6_addr (const char * host)<br>
>> +{<br>
>> + const char * p;<br>
>> + unsigned colons = 0, nums = 0, decs = 0, dots = 0;<br>
>> + if (!host)<br>
>> + {<br>
>> + return 0;<br>
>> + }<br>
>> + for (p = host; *p; p++)<br>
>> + {<br>
>> + char c = *p;<br>
>> + if (c == ':')<br>
>> + {<br>
>> + colons ++;<br>
>> + if (nums > 4)<br>
>> + {<br>
>> + return 0;<br>
>> + }<br>
>> + nums = 0;<br>
>> + decs = 0;<br>
>> + }<br>
>> + else if (('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || ('a' <= c &&<br>
>> c <= 'f')) + {<br>
>> + if ('0' <= c && c <= '9')<br>
>> + {<br>
>> + decs ++;<br>
>> + }<br>
>> + nums ++;<br>
>> + }<br>
>> + else if (c == '.')<br>
>> + {<br>
>> + dots ++;<br>
>> + if (nums != decs)<br>
>> + {<br>
>> + return 0;<br>
>> + }<br>
>> + if (nums == 0 || 3 < nums)<br>
>> + {<br>
>> + return 0;<br>
>> + }<br>
>> + }<br>
>> + else<br>
>> + {<br>
>> + return 0;<br>
>> + }<br>
>> + }<br>
>> + return 2 <= colons && colons <= 7 && (dots == 0 || dots == 3);<br>
>> +}<br>
>> +<br>
> This does not need so much complexity. If you really want to check for IPv6,<br>
> there's inet_pton(), but you could just check if the string contains as colon.<br>
><br>
> Also please try to stick to the same indentation style as the rest of the<br>
> code.<br>
><br>
>> void ConnectionParams::parse()<br>
>> {<br>
>> vlc_url_t url_components;<br>
</div>
</span></font><br>
</div>
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</body>
</html>