[vlc-devel] [PATCH] DASH: fix URL parsing

fyhuel at viotech.net fyhuel at viotech.net
Wed Feb 22 10:43:33 CET 2012


From: Frédéric Yhuel <fyhuel at viotech.net>

use vlc_UrlParse() instead of home made code and handle the case where the
port is not equal to 80.
---
 modules/stream_filter/dash/http/HTTPConnection.cpp |   15 +++++++--------
 modules/stream_filter/dash/http/HTTPConnection.h   |    1 +
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/modules/stream_filter/dash/http/HTTPConnection.cpp b/modules/stream_filter/dash/http/HTTPConnection.cpp
index f98c9c7..a764fa7 100644
--- a/modules/stream_filter/dash/http/HTTPConnection.cpp
+++ b/modules/stream_filter/dash/http/HTTPConnection.cpp
@@ -26,6 +26,7 @@
 #endif
 
 #include "HTTPConnection.h"
+#include <vlc_url.h>
 
 using namespace dash::http;
 
@@ -74,14 +75,12 @@ int             HTTPConnection::peek            (const uint8_t **pp_peek, size_t
 }
 void            HTTPConnection::parseURL        ()
 {
-    this->hostname = this->url;
-    this->hostname.erase(0, 7);
-    this->path = this->hostname;
+    vlc_url_t url_components;
+    vlc_UrlParse(&url_components, this->url.c_str(), 0);
+    this->hostname.assign(url_components.psz_host);
+    this->path.assign(url_components.psz_path);
+    this->port = url_components.i_port ? url_components.i_port : 80;
 
-    size_t pos = this->hostname.find("/");
-
-    this->hostname  = this->hostname.substr(0, pos);
-    this->path      = this->path.substr(pos, this->path.size());
 
     this->request = "GET " + this->path + " HTTP/1.1\r\n" +
                     "Host: " + this->hostname + "\r\nConnection: close\r\n\r\n";
@@ -110,7 +109,7 @@ bool            HTTPConnection::init            ()
     this->parseURL();
     this->prepareRequest();
 
-    this->httpSocket = net_ConnectTCP(this->stream, this->hostname.c_str(), 80);
+    this->httpSocket = net_ConnectTCP(this->stream, this->hostname.c_str(), this->port);
 
     if(this->sendData(this->request))
         return this->parseHeader();
diff --git a/modules/stream_filter/dash/http/HTTPConnection.h b/modules/stream_filter/dash/http/HTTPConnection.h
index 7cb97a0..19826bc 100644
--- a/modules/stream_filter/dash/http/HTTPConnection.h
+++ b/modules/stream_filter/dash/http/HTTPConnection.h
@@ -61,6 +61,7 @@ namespace dash
                 std::string             url;
                 std::string             hostname;
                 std::string             path;
+                int                     port;
                 std::string             request;
                 stream_t                *stream;
                 Chunk                   *chunk;
-- 
1.7.5.4




More information about the vlc-devel mailing list