Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
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-2-2
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
Show 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 @@
...
@@ -26,16 +26,14 @@
#endif
#endif
#include "HTTPConnection.h"
#include "HTTPConnection.h"
#include <vlc_url.h>
using
namespace
dash
::
http
;
using
namespace
dash
::
http
;
HTTPConnection
::
HTTPConnection
(
Chunk
*
chunk
,
stream_t
*
stream
)
:
HTTPConnection
::
HTTPConnection
(
stream_t
*
stream
)
:
stream
(
stream
),
stream
(
stream
),
chunk
(
chunk
),
peekBufferLen
(
0
),
peekBufferLen
(
0
)
contentLength
(
0
)
{
{
this
->
url
=
chunk
->
getUrl
();
this
->
peekBuffer
=
new
uint8_t
[
PEEKBUFFER
];
this
->
peekBuffer
=
new
uint8_t
[
PEEKBUFFER
];
}
}
HTTPConnection
::~
HTTPConnection
()
HTTPConnection
::~
HTTPConnection
()
...
@@ -73,48 +71,41 @@ int HTTPConnection::peek (const uint8_t **pp_peek, size_t
...
@@ -73,48 +71,41 @@ int HTTPConnection::peek (const uint8_t **pp_peek, size_t
*
pp_peek
=
peek
;
*
pp_peek
=
peek
;
return
size
;
return
size
;
}
}
void
HTTPConnection
::
parseURL
(
)
std
::
string
HTTPConnection
::
prepareRequest
(
Chunk
*
chunk
)
{
{
vlc_url_t
url_components
;
std
::
string
request
;
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
=
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
())
if
(
!
chunk
->
useByteRange
())
{
{
this
->
request
=
"GET "
+
this
->
path
+
" HTTP/1.1"
+
"
\r\n
"
+
request
=
"GET "
+
chunk
->
getPath
()
+
" HTTP/1.1"
+
"
\r\n
"
+
"Host: "
+
this
->
hostname
+
"
\r\n
"
+
"Host: "
+
chunk
->
getHostname
()
+
"
\r\n
"
+
"Connection: close
\r\n\r\n
"
;
"Connection: close
\r\n\r\n
"
;
}
}
else
else
{
{
std
::
stringstream
req
;
std
::
stringstream
req
;
req
<<
"GET "
<<
this
->
path
<<
" HTTP/1.1
\r\n
"
<<
req
<<
"GET "
<<
chunk
->
getPath
()
<<
" HTTP/1.1
\r\n
"
<<
"Host: "
<<
this
->
hostname
<<
"
\r\n
"
<<
"Host: "
<<
chunk
->
getHostname
()
<<
"
\r\n
"
<<
"Range: bytes="
<<
this
->
chunk
->
getStartByte
()
<<
"-"
<<
this
->
chunk
->
getEndByte
()
<<
"
\r\n
"
<<
"Range: bytes="
<<
chunk
->
getStartByte
()
<<
"-"
<<
chunk
->
getEndByte
()
<<
"
\r\n
"
<<
"Connection: close
\r\n\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
();
if
(
!
chunk
->
hasHostname
())
this
->
prepareRequest
();
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
this
->
parseHeader
();
return
false
;
return
false
;
...
@@ -123,9 +114,18 @@ bool HTTPConnection::parseHeader ()
...
@@ -123,9 +114,18 @@ bool HTTPConnection::parseHeader ()
{
{
std
::
string
line
=
this
->
readLine
();
std
::
string
line
=
this
->
readLine
();
if
(
line
.
size
()
==
0
)
return
false
;
while
(
line
.
compare
(
"
\r\n
"
))
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
();
line
=
this
->
readLine
();
if
(
line
.
size
()
==
0
)
return
false
;
}
}
return
true
;
return
true
;
...
@@ -148,7 +148,7 @@ std::string HTTPConnection::readLine ()
...
@@ -148,7 +148,7 @@ std::string HTTPConnection::readLine ()
if
(
size
>
0
)
if
(
size
>
0
)
return
ss
.
str
();
return
ss
.
str
();
return
"
\r\n
"
;
return
""
;
}
}
bool
HTTPConnection
::
sendData
(
const
std
::
string
&
data
)
bool
HTTPConnection
::
sendData
(
const
std
::
string
&
data
)
{
{
...
@@ -168,3 +168,11 @@ void HTTPConnection::closeSocket ()
...
@@ -168,3 +168,11 @@ void HTTPConnection::closeSocket ()
{
{
net_Close
(
this
->
httpSocket
);
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
...
@@ -48,32 +48,26 @@ namespace dash
class
HTTPConnection
:
public
IHTTPConnection
class
HTTPConnection
:
public
IHTTPConnection
{
{
public:
public:
HTTPConnection
(
Chunk
*
chunk
,
stream_t
*
stream
);
HTTPConnection
(
stream_t
*
stream
);
virtual
~
HTTPConnection
();
virtual
~
HTTPConnection
();
bool
init
(
);
virtual
bool
init
(
Chunk
*
chunk
);
void
closeSocket
();
void
closeSocket
();
virtual
int
read
(
void
*
p_buffer
,
size_t
len
);
virtual
int
read
(
void
*
p_buffer
,
size_t
len
);
virtual
int
peek
(
const
uint8_t
**
pp_peek
,
size_t
i_peek
);
virtual
int
peek
(
const
uint8_t
**
pp_peek
,
size_t
i_peek
);
pr
ivate
:
pr
otected
:
int
httpSocket
;
int
httpSocket
;
std
::
string
url
;
std
::
string
hostname
;
std
::
string
path
;
int
port
;
std
::
string
request
;
stream_t
*
stream
;
stream_t
*
stream
;
Chunk
*
chunk
;
uint8_t
*
peekBuffer
;
uint8_t
*
peekBuffer
;
size_t
peekBufferLen
;
size_t
peekBufferLen
;
int
contentLength
;
void
parseURL
();
bool
sendData
(
const
std
::
string
&
data
);
bool
sendData
(
const
std
::
string
&
data
);
bool
parseHeader
();
bool
parseHeader
();
std
::
string
readLine
();
std
::
string
readLine
();
void
prepareRequest
();
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
...
@@ -137,8 +137,8 @@ int HTTPConnectionManager::peek (Chunk *chun
IHTTPConnection
*
HTTPConnectionManager
::
initConnection
(
Chunk
*
chunk
)
IHTTPConnection
*
HTTPConnectionManager
::
initConnection
(
Chunk
*
chunk
)
{
{
HTTPConnection
*
con
=
new
HTTPConnection
(
chunk
,
this
->
stream
);
HTTPConnection
*
con
=
new
HTTPConnection
(
this
->
stream
);
if
(
con
->
init
()
==
false
)
if
(
con
->
init
(
chunk
)
==
false
)
return
NULL
;
return
NULL
;
this
->
chunkMap
[
chunk
]
=
con
;
this
->
chunkMap
[
chunk
]
=
con
;
this
->
chunkCount
++
;
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