[vlc-commits] demux: adaptive: use custom status for http queries

Francois Cartegnie git at videolan.org
Fri Oct 12 17:15:44 CEST 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Oct 12 11:03:43 2018 +0200| [4c2ba7cceda69d4e2a558906dec030bcf5167001] | committer: Francois Cartegnie

demux: adaptive: use custom status for http queries

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

 modules/demux/adaptive/http/Chunk.cpp            |  7 +++--
 modules/demux/adaptive/http/ConnectionParams.hpp |  9 ++++++
 modules/demux/adaptive/http/HTTPConnection.cpp   | 39 +++++++++++++-----------
 modules/demux/adaptive/http/HTTPConnection.hpp   | 11 ++++---
 4 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index eb0532b6a0..0674231ee5 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -250,10 +250,11 @@ bool HTTPChunkSource::prepare()
                 break;
         }
 
-        int i_ret = connection->request(connparams.getPath(), bytesRange);
-        if(i_ret != VLC_SUCCESS)
+        enum RequestStatus status =
+                connection->request(connparams.getPath(), bytesRange);
+        if(status != RequestStatus::Success)
         {
-            if(i_ret == VLC_ETIMEOUT) /* redirection */
+            if(status == RequestStatus::Redirection)
             {
                 HTTPConnection *httpconn = dynamic_cast<HTTPConnection *>(connection);
                 if(httpconn)
diff --git a/modules/demux/adaptive/http/ConnectionParams.hpp b/modules/demux/adaptive/http/ConnectionParams.hpp
index e8cf5cec7c..5730ba9c63 100644
--- a/modules/demux/adaptive/http/ConnectionParams.hpp
+++ b/modules/demux/adaptive/http/ConnectionParams.hpp
@@ -29,6 +29,15 @@ namespace adaptive
     {
         class Transport;
 
+        enum RequestStatus
+        {
+            Success,
+            Redirection,
+            Unauthorized,
+            NotFound,
+            GenericError,
+        };
+
         class BackendPrefInterface
         {
             /* Design Hack for now to force fallback on regular access
diff --git a/modules/demux/adaptive/http/HTTPConnection.cpp b/modules/demux/adaptive/http/HTTPConnection.cpp
index 451e81d2bd..1924368827 100644
--- a/modules/demux/adaptive/http/HTTPConnection.cpp
+++ b/modules/demux/adaptive/http/HTTPConnection.cpp
@@ -133,7 +133,8 @@ void HTTPConnection::disconnect()
     transport->disconnect();
 }
 
-int HTTPConnection::request(const std::string &path, const BytesRange &range)
+enum RequestStatus
+    HTTPConnection::request(const std::string &path, const BytesRange &range)
 {
     queryOk = false;
     chunked = false;
@@ -156,7 +157,7 @@ int HTTPConnection::request(const std::string &path, const BytesRange &range)
     else querypath = path;
 
     if(!connected() && ( params.getHostname().empty() || !connect() ))
-        return VLC_EGENERIC;
+        return RequestStatus::GenericError;
 
     bytesRange = range;
     if(range.isValid() && range.getEndByte() > 0)
@@ -176,19 +177,19 @@ int HTTPConnection::request(const std::string &path, const BytesRange &range)
             connectionClose = true;
             return request(path, range);
         }
-        return VLC_EGENERIC;
+        return RequestStatus::GenericError;
     }
 
-    int i_ret = parseReply();
-    if(i_ret == VLC_SUCCESS)
+    enum RequestStatus status = parseReply();
+    if(status == RequestStatus::Success)
     {
         queryOk = true;
     }
-    else if(i_ret == VLC_ETIMEOUT) /* redir */
+    else if(status == RequestStatus::Redirection)
     {
         transport->disconnect();
     }
-    else if(i_ret == VLC_EGENERIC)
+    else if(status == RequestStatus::GenericError)
     {
         transport->disconnect();
         if(!connectionClose)
@@ -198,7 +199,7 @@ int HTTPConnection::request(const std::string &path, const BytesRange &range)
         }
     }
 
-    return i_ret;
+    return status;
 }
 
 ssize_t HTTPConnection::read(void *p_buffer, size_t len)
@@ -244,17 +245,18 @@ bool HTTPConnection::send(const void *buf, size_t size)
     return transport->send(buf, size);
 }
 
-int HTTPConnection::parseReply()
+enum RequestStatus
+    HTTPConnection::parseReply()
 {
     std::string statusline = readLine();
 
     if(statusline.empty())
-        return VLC_EGENERIC;
+        return RequestStatus::GenericError;
 
     if (statusline.compare(0, 9, "HTTP/1.1 ")!=0)
     {
         if(statusline.compare(0, 9, "HTTP/1.0 ")!=0)
-            return VLC_ENOOBJ;
+            return RequestStatus::NotFound;
         else
             connectionClose = true;
     }
@@ -287,15 +289,15 @@ int HTTPConnection::parseReply()
        !locationparams.getUrl().empty())
     {
         msg_Info(p_object, "%d redirection to %s", replycode, locationparams.getUrl().c_str());
-        return VLC_ETIMEOUT;
+        return RequestStatus::Redirection;
     }
     else if (replycode != 200 && replycode != 206)
     {
         msg_Err(p_object, "Failed reading %s: %s", params.getUrl().c_str(), statusline.c_str());
-        return VLC_ENOOBJ;
+        return RequestStatus::NotFound;
     }
 
-    return VLC_SUCCESS;
+    return RequestStatus::Success;
 }
 
 ssize_t HTTPConnection::readChunk(void *p_buffer, size_t len)
@@ -486,7 +488,8 @@ bool StreamUrlConnection::canReuse(const ConnectionParams &params) const
     return available && params.usesAccess();
 }
 
-int StreamUrlConnection::request(const std::string &path, const BytesRange &range)
+enum RequestStatus
+    StreamUrlConnection::request(const std::string &path, const BytesRange &range)
 {
     reset();
 
@@ -498,7 +501,7 @@ int StreamUrlConnection::request(const std::string &path, const BytesRange &rang
 
     p_streamurl = vlc_stream_NewURL(p_object, params.getUrl().c_str());
     if(!p_streamurl)
-        return VLC_EGENERIC;
+        return RequestStatus::GenericError;
 
     char *psz_type = stream_ContentType(p_streamurl);
     if(psz_type)
@@ -516,7 +519,7 @@ int StreamUrlConnection::request(const std::string &path, const BytesRange &rang
         if(vlc_stream_Seek(p_streamurl, range.getStartByte()) != VLC_SUCCESS)
         {
             vlc_stream_Delete(p_streamurl);
-            return VLC_EGENERIC;
+            return RequestStatus::GenericError;
         }
         bytesRange = range;
         contentLength = range.getEndByte() - range.getStartByte() + 1;
@@ -528,7 +531,7 @@ int StreamUrlConnection::request(const std::string &path, const BytesRange &rang
         if(!range.isValid() || contentLength > (size_t) i_size)
             contentLength = (size_t) i_size;
     }
-    return VLC_SUCCESS;
+    return RequestStatus::Success;
 }
 
 ssize_t StreamUrlConnection::read(void *p_buffer, size_t len)
diff --git a/modules/demux/adaptive/http/HTTPConnection.hpp b/modules/demux/adaptive/http/HTTPConnection.hpp
index c95ce15798..50ef844ab8 100644
--- a/modules/demux/adaptive/http/HTTPConnection.hpp
+++ b/modules/demux/adaptive/http/HTTPConnection.hpp
@@ -46,7 +46,8 @@ namespace adaptive
                 virtual bool    prepare     (const ConnectionParams &);
                 virtual bool    canReuse     (const ConnectionParams &) const = 0;
 
-                virtual int     request     (const std::string& path, const BytesRange & = BytesRange()) = 0;
+                virtual enum RequestStatus
+                                request     (const std::string& path, const BytesRange & = BytesRange()) = 0;
                 virtual ssize_t read        (void *p_buffer, size_t len) = 0;
 
                 virtual size_t  getContentLength() const;
@@ -71,7 +72,8 @@ namespace adaptive
                 virtual ~HTTPConnection();
 
                 virtual bool    canReuse     (const ConnectionParams &) const;
-                virtual int     request     (const std::string& path, const BytesRange & = BytesRange());
+                virtual enum RequestStatus
+                                request     (const std::string& path, const BytesRange & = BytesRange());
                 virtual ssize_t read        (void *p_buffer, size_t len);
 
                 void setUsed( bool );
@@ -91,7 +93,7 @@ namespace adaptive
                 virtual std::string buildRequestHeader(const std::string &path) const;
 
                 ssize_t         readChunk   (void *p_buffer, size_t len);
-                int parseReply();
+                enum RequestStatus parseReply();
                 std::string readLine();
                 char * psz_useragent;
 
@@ -118,7 +120,8 @@ namespace adaptive
 
                 virtual bool    canReuse     (const ConnectionParams &) const;
 
-                virtual int     request     (const std::string& path, const BytesRange & = BytesRange());
+                virtual enum RequestStatus
+                                request     (const std::string& path, const BytesRange & = BytesRange());
                 virtual ssize_t read        (void *p_buffer, size_t len);
 
                 virtual void    setUsed( bool );



More information about the vlc-commits mailing list