RTSP authentication support improvements
This commit is contained in:
parent
3977bad570
commit
786ff05767
2 changed files with 19 additions and 12 deletions
|
@ -20,6 +20,7 @@ namespace Mist{
|
||||||
void InputRTSP::incomingRTP(const uint64_t track, const RTP::Packet &p){sdpState.handleIncomingRTP(track, p);}
|
void InputRTSP::incomingRTP(const uint64_t track, const RTP::Packet &p){sdpState.handleIncomingRTP(track, p);}
|
||||||
|
|
||||||
InputRTSP::InputRTSP(Util::Config *cfg) : Input(cfg){
|
InputRTSP::InputRTSP(Util::Config *cfg) : Input(cfg){
|
||||||
|
needAuth = false;
|
||||||
TCPmode = true;
|
TCPmode = true;
|
||||||
sdpState.myMeta = &myMeta;
|
sdpState.myMeta = &myMeta;
|
||||||
sdpState.incomingPacketCallback = incomingPacket;
|
sdpState.incomingPacketCallback = incomingPacket;
|
||||||
|
@ -80,7 +81,8 @@ namespace Mist{
|
||||||
|
|
||||||
void InputRTSP::sendCommand(const std::string &cmd, const std::string &cUrl,
|
void InputRTSP::sendCommand(const std::string &cmd, const std::string &cUrl,
|
||||||
const std::string &body,
|
const std::string &body,
|
||||||
const std::map<std::string, std::string> *extraHeaders){
|
const std::map<std::string, std::string> *extraHeaders,
|
||||||
|
bool reAuth){
|
||||||
++cSeq;
|
++cSeq;
|
||||||
sndH.Clean();
|
sndH.Clean();
|
||||||
sndH.protocol = "RTSP/1.0";
|
sndH.protocol = "RTSP/1.0";
|
||||||
|
@ -100,6 +102,15 @@ namespace Mist{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sndH.SendRequest(tcpCon, "", true);
|
sndH.SendRequest(tcpCon, "", true);
|
||||||
|
parsePacket();
|
||||||
|
|
||||||
|
if (reAuth && needAuth && authRequest.size() && (username.size() || password.size()) && tcpCon){
|
||||||
|
INFO_MSG("Authenticating %s...", cmd.c_str());
|
||||||
|
sendCommand(cmd, cUrl, body, extraHeaders, false);
|
||||||
|
if (needAuth){
|
||||||
|
FAIL_MSG("Authentication failed! Are the provided credentials correct?");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputRTSP::checkArguments(){
|
bool InputRTSP::checkArguments(){
|
||||||
|
@ -129,17 +140,11 @@ namespace Mist{
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRTSP::parseStreamHeader(){
|
void InputRTSP::parseStreamHeader(){
|
||||||
|
tcpCon.setBlocking(false);
|
||||||
std::map<std::string, std::string> extraHeaders;
|
std::map<std::string, std::string> extraHeaders;
|
||||||
sendCommand("OPTIONS", url.getUrl(), "");
|
sendCommand("OPTIONS", url.getUrl(), "");
|
||||||
parsePacket();
|
|
||||||
extraHeaders["Accept"] = "application/sdp";
|
extraHeaders["Accept"] = "application/sdp";
|
||||||
sendCommand("DESCRIBE", url.getUrl(), "", &extraHeaders);
|
sendCommand("DESCRIBE", url.getUrl(), "", &extraHeaders);
|
||||||
parsePacket();
|
|
||||||
if (!seenSDP && authRequest.size() && (username.size() || password.size()) && tcpCon){
|
|
||||||
INFO_MSG("Authenticating...");
|
|
||||||
sendCommand("DESCRIBE", url.getUrl(), "", &extraHeaders);
|
|
||||||
parsePacket();
|
|
||||||
}
|
|
||||||
if (!tcpCon || !seenSDP){
|
if (!tcpCon || !seenSDP){
|
||||||
FAIL_MSG("Could not get stream description!");
|
FAIL_MSG("Could not get stream description!");
|
||||||
return;
|
return;
|
||||||
|
@ -151,7 +156,6 @@ namespace Mist{
|
||||||
extraHeaders.clear();
|
extraHeaders.clear();
|
||||||
extraHeaders["Transport"] = it->second.generateTransport(it->first, url.host, TCPmode);
|
extraHeaders["Transport"] = it->second.generateTransport(it->first, url.host, TCPmode);
|
||||||
sendCommand("SETUP", url.link(it->second.control).getUrl(), "", &extraHeaders);
|
sendCommand("SETUP", url.link(it->second.control).getUrl(), "", &extraHeaders);
|
||||||
parsePacket();
|
|
||||||
if (!tcpCon || !transportSet){
|
if (!tcpCon || !transportSet){
|
||||||
FAIL_MSG("Could not setup track %s!", myMeta.tracks[it->first].getIdentifier().c_str());
|
FAIL_MSG("Could not setup track %s!", myMeta.tracks[it->first].getIdentifier().c_str());
|
||||||
tcpCon.close();
|
tcpCon.close();
|
||||||
|
@ -164,8 +168,9 @@ namespace Mist{
|
||||||
extraHeaders["Range"] = "npt=0.000-";
|
extraHeaders["Range"] = "npt=0.000-";
|
||||||
sendCommand("PLAY", url.getUrl(), "", &extraHeaders);
|
sendCommand("PLAY", url.getUrl(), "", &extraHeaders);
|
||||||
if (!TCPmode){
|
if (!TCPmode){
|
||||||
tcpCon.setBlocking(false);
|
|
||||||
connectedAt = Util::epoch() + 2208988800ll;
|
connectedAt = Util::epoch() + 2208988800ll;
|
||||||
|
}else{
|
||||||
|
tcpCon.setBlocking(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +215,8 @@ namespace Mist{
|
||||||
if (recH.hasHeader("WWW-Authenticate")){
|
if (recH.hasHeader("WWW-Authenticate")){
|
||||||
authRequest = recH.GetHeader("WWW-Authenticate");
|
authRequest = recH.GetHeader("WWW-Authenticate");
|
||||||
}
|
}
|
||||||
if (recH.url == "401"){
|
needAuth = (recH.url == "401");
|
||||||
|
if (needAuth){
|
||||||
INFO_MSG("Requires authentication");
|
INFO_MSG("Requires authentication");
|
||||||
recH.Clean();
|
recH.Clean();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace Mist{
|
||||||
void parseStreamHeader();
|
void parseStreamHeader();
|
||||||
void seek(int seekTime){}
|
void seek(int seekTime){}
|
||||||
void sendCommand(const std::string &cmd, const std::string &cUrl, const std::string &body,
|
void sendCommand(const std::string &cmd, const std::string &cUrl, const std::string &body,
|
||||||
const std::map<std::string, std::string> *extraHeaders = 0);
|
const std::map<std::string, std::string> *extraHeaders = 0, bool reAuth=true);
|
||||||
bool parsePacket();
|
bool parsePacket();
|
||||||
bool handleUDP();
|
bool handleUDP();
|
||||||
std::string streamMainLoop();
|
std::string streamMainLoop();
|
||||||
|
@ -40,6 +40,7 @@ namespace Mist{
|
||||||
bool seenSDP;
|
bool seenSDP;
|
||||||
bool transportSet;
|
bool transportSet;
|
||||||
bool TCPmode;
|
bool TCPmode;
|
||||||
|
bool needAuth;
|
||||||
std::string session;
|
std::string session;
|
||||||
long long connectedAt; ///< The timestamp the connection was made, as reference point for RTCP
|
long long connectedAt; ///< The timestamp the connection was made, as reference point for RTCP
|
||||||
/// packets.
|
/// packets.
|
||||||
|
|
Loading…
Add table
Reference in a new issue