[vlc-commits] DASH: fix URL parsing

Frédéric Yhuel git at videolan.org
Wed Feb 22 14:29:01 CET 2012


vlc | branch: master | Frédéric Yhuel <fyhuel at viotech.net> | Wed Feb 22 13:27:29 2012 +0100| [06339a5e0fa9340adb15320dd9e1700da50c040c] | committer: Hugo Beauzée-Luyssen

DASH: fix URL parsing

use vlc_UrlParse() instead of home made code and handle the case where
the port is not equal to 80.

Signed-off-by: Hugo Beauzée-Luyssen <beauze.h at gmail.com>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=06339a5e0fa9340adb15320dd9e1700da50c040c
---

 modules/stream_filter/dash/http/HTTPConnection.cpp |   22 +++++++------------
 modules/stream_filter/dash/http/HTTPConnection.h   |    1 +
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/modules/stream_filter/dash/http/HTTPConnection.cpp b/modules/stream_filter/dash/http/HTTPConnection.cpp
index 951df6f..13f572a 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,22 +75,15 @@ int             HTTPConnection::peek            (const uint8_t **pp_peek, size_t
 }
 void            HTTPConnection::parseURL        ()
 {
+    vlc_url_t url_components;
+    vlc_UrlParse(&url_components, this->url.c_str(), 0);
+    this->path = url_components.psz_path;
+    this->port = url_components.i_port ? url_components.i_port : 80;
+
     if(this->url.compare(0, 4, "http"))
-    {
         this->hostname = Helper::combinePaths(Helper::getDirectoryPath(stream->psz_path), this->url);
-    }
     else
-    {
-        this->hostname = this->url;
-        this->hostname.erase(0, 7);
-    }
-
-    this->path = this->hostname;
-
-    size_t pos = this->hostname.find("/");
-
-    this->hostname  = this->hostname.substr(0, pos);
-    this->path      = this->path.substr(pos, this->path.size());
+        this->hostname = url_components.psz_host;
 
     this->request = "GET " + this->path + " HTTP/1.1\r\n" +
                     "Host: " + this->hostname + "\r\nConnection: close\r\n\r\n";
@@ -118,7 +112,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 978ff2e..f27b152 100644
--- a/modules/stream_filter/dash/http/HTTPConnection.h
+++ b/modules/stream_filter/dash/http/HTTPConnection.h
@@ -62,6 +62,7 @@ namespace dash
                 std::string             url;
                 std::string             hostname;
                 std::string             path;
+                int                     port;
                 std::string             request;
                 stream_t                *stream;
                 Chunk                   *chunk;



More information about the vlc-commits mailing list