Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
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
videolan
vlc
Commits
60ceaa11
Commit
60ceaa11
authored
Mar 09, 2012
by
Christopher Mueller
Committed by
Hugo Beauzée-Luyssen
Mar 20, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dash: refactored HTTPConnection
Signed-off-by:
Hugo Beauzée-Luyssen
<
beauze.h@gmail.com
>
parent
1cad10dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
55 deletions
+57
-55
modules/stream_filter/dash/http/HTTPConnection.cpp
modules/stream_filter/dash/http/HTTPConnection.cpp
+41
-33
modules/stream_filter/dash/http/HTTPConnection.h
modules/stream_filter/dash/http/HTTPConnection.h
+14
-20
modules/stream_filter/dash/http/HTTPConnectionManager.cpp
modules/stream_filter/dash/http/HTTPConnectionManager.cpp
+2
-2
No files found.
modules/stream_filter/dash/http/HTTPConnection.cpp
View file @
60ceaa11
...
...
@@ -26,16 +26,14 @@
#endif
#include "HTTPConnection.h"
#include <vlc_url.h>
using
namespace
dash
::
http
;
HTTPConnection
::
HTTPConnection
(
Chunk
*
chunk
,
stream_t
*
stream
)
:
HTTPConnection
::
HTTPConnection
(
stream_t
*
stream
)
:
stream
(
stream
),
chunk
(
chunk
),
peekBufferLen
(
0
)
peekBufferLen
(
0
),
contentLength
(
0
)
{
this
->
url
=
chunk
->
getUrl
();
this
->
peekBuffer
=
new
uint8_t
[
PEEKBUFFER
];
}
HTTPConnection
::~
HTTPConnection
()
...
...
@@ -73,48 +71,41 @@ int HTTPConnection::peek (const uint8_t **pp_peek, size_t
*
pp_peek
=
peek
;
return
size
;
}
void
HTTPConnection
::
parseURL
(
)
std
::
string
HTTPConnection
::
prepareRequest
(
Chunk
*
chunk
)
{
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
;
std
::
string
request
;
if
(
this
->
url
.
compare
(
0
,
4
,
"http"
))
this
->
hostname
=
Helper
::
combinePaths
(
Helper
::
getDirectoryPath
(
stream
->
psz_path
),
this
->
url
);
else
this
->
hostname
=
url_components
.
psz_host
;
this
->
request
=
"GET "
+
this
->
path
+
" HTTP/1.1
\r\n
"
+
"Host: "
+
this
->
hostname
+
"
\r\n
Connection: close
\r\n\r\n
"
;
}
void
HTTPConnection
::
prepareRequest
()
{
if
(
!
chunk
->
useByteRange
())
{
this
->
request
=
"GET "
+
this
->
path
+
" HTTP/1.1"
+
"
\r\n
"
+
"Host: "
+
this
->
hostname
+
"
\r\n
"
+
"Connection: close
\r\n\r\n
"
;
request
=
"GET "
+
chunk
->
getPath
()
+
" HTTP/1.1"
+
"
\r\n
"
+
"Host: "
+
chunk
->
getHostname
()
+
"
\r\n
"
+
"Connection: close
\r\n\r\n
"
;
}
else
{
std
::
stringstream
req
;
req
<<
"GET "
<<
this
->
path
<<
" HTTP/1.1
\r\n
"
<<
"Host: "
<<
this
->
hostname
<<
"
\r\n
"
<<
"Range: bytes="
<<
this
->
chunk
->
getStartByte
()
<<
"-"
<<
this
->
chunk
->
getEndByte
()
<<
"
\r\n
"
<<
req
<<
"GET "
<<
chunk
->
getPath
()
<<
" HTTP/1.1
\r\n
"
<<
"Host: "
<<
chunk
->
getHostname
()
<<
"
\r\n
"
<<
"Range: bytes="
<<
chunk
->
getStartByte
()
<<
"-"
<<
chunk
->
getEndByte
()
<<
"
\r\n
"
<<
"Connection: close
\r\n\r\n
"
;
this
->
request
=
req
.
str
();
request
=
req
.
str
();
}
return
request
;
}
bool
HTTPConnection
::
init
()
bool
HTTPConnection
::
init
(
Chunk
*
chunk
)
{
this
->
parseURL
();
this
->
prepareRequest
();
if
(
!
chunk
->
hasHostname
())
if
(
!
this
->
setUrlRelative
(
chunk
))
return
false
;
this
->
httpSocket
=
net_ConnectTCP
(
this
->
stream
,
chunk
->
getHostname
().
c_str
(),
chunk
->
getPort
());
this
->
httpSocket
=
net_ConnectTCP
(
this
->
stream
,
this
->
hostname
.
c_str
(),
this
->
port
);
if
(
this
->
httpSocket
==
-
1
)
return
false
;
if
(
this
->
sendData
(
this
->
request
))
if
(
this
->
sendData
(
this
->
prepareRequest
(
chunk
)
))
return
this
->
parseHeader
();
return
false
;
...
...
@@ -123,9 +114,18 @@ bool HTTPConnection::parseHeader ()
{
std
::
string
line
=
this
->
readLine
();
if
(
line
.
size
()
==
0
)
return
false
;
while
(
line
.
compare
(
"
\r\n
"
))
{
if
(
!
line
.
compare
(
0
,
14
,
"Content-Length"
))
this
->
contentLength
=
atoi
(
line
.
substr
(
15
,
line
.
size
()).
c_str
());
line
=
this
->
readLine
();
if
(
line
.
size
()
==
0
)
return
false
;
}
return
true
;
...
...
@@ -148,7 +148,7 @@ std::string HTTPConnection::readLine ()
if
(
size
>
0
)
return
ss
.
str
();
return
"
\r\n
"
;
return
""
;
}
bool
HTTPConnection
::
sendData
(
const
std
::
string
&
data
)
{
...
...
@@ -168,3 +168,11 @@ void HTTPConnection::closeSocket ()
{
net_Close
(
this
->
httpSocket
);
}
bool
HTTPConnection
::
setUrlRelative
(
Chunk
*
chunk
)
{
std
::
stringstream
ss
;
ss
<<
stream
->
psz_access
<<
"://"
<<
Helper
::
combinePaths
(
Helper
::
getDirectoryPath
(
stream
->
psz_path
),
chunk
->
getUrl
());
chunk
->
setUrl
(
ss
.
str
());
return
chunk
->
hasHostname
();
}
modules/stream_filter/dash/http/HTTPConnection.h
View file @
60ceaa11
...
...
@@ -48,32 +48,26 @@ namespace dash
class
HTTPConnection
:
public
IHTTPConnection
{
public:
HTTPConnection
(
Chunk
*
chunk
,
stream_t
*
stream
);
HTTPConnection
(
stream_t
*
stream
);
virtual
~
HTTPConnection
();
bool
init
();
void
closeSocket
();
virtual
bool
init
(
Chunk
*
chunk
);
void
closeSocket
();
virtual
int
read
(
void
*
p_buffer
,
size_t
len
);
virtual
int
peek
(
const
uint8_t
**
pp_peek
,
size_t
i_peek
);
private:
int
httpSocket
;
std
::
string
url
;
std
::
string
hostname
;
std
::
string
path
;
int
port
;
std
::
string
request
;
stream_t
*
stream
;
Chunk
*
chunk
;
uint8_t
*
peekBuffer
;
size_t
peekBufferLen
;
protected:
int
httpSocket
;
stream_t
*
stream
;
uint8_t
*
peekBuffer
;
size_t
peekBufferLen
;
int
contentLength
;
void
parseURL
(
);
bool
sendData
(
const
std
::
string
&
data
);
bool
parseHeader
();
std
::
string
readLine
(
);
void
prepareRequest
(
);
bool
sendData
(
const
std
::
string
&
data
);
bool
parseHeader
(
);
std
::
string
readLine
();
virtual
std
::
string
prepareRequest
(
Chunk
*
chunk
);
bool
setUrlRelative
(
Chunk
*
chunk
);
};
}
}
...
...
modules/stream_filter/dash/http/HTTPConnectionManager.cpp
View file @
60ceaa11
...
...
@@ -137,8 +137,8 @@ int HTTPConnectionManager::peek (Chunk *chun
IHTTPConnection
*
HTTPConnectionManager
::
initConnection
(
Chunk
*
chunk
)
{
HTTPConnection
*
con
=
new
HTTPConnection
(
chunk
,
this
->
stream
);
if
(
con
->
init
()
==
false
)
HTTPConnection
*
con
=
new
HTTPConnection
(
this
->
stream
);
if
(
con
->
init
(
chunk
)
==
false
)
return
NULL
;
this
->
chunkMap
[
chunk
]
=
con
;
this
->
chunkCount
++
;
...
...
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