Support newer HTTP versions in IceCast2 codebase
* Some servers pretending to be IceCast 2 might return newer version than 1.0. The example server that happens to do that is Cast ( https://github.com/innovate-technologies/Cast ). * Replacing HTTP/1.0 with HTTP/1.[0-9] regex makes sure that we handle newer versions properly instead of showing: "Icecast2 - Unexpected response from server".
This commit is contained in:
parent
d3825f3e17
commit
0560b554b1
|
@ -51,6 +51,7 @@
|
||||||
#error need math.h
|
#error need math.h
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
@ -73,9 +74,10 @@ static const char fileid[] = "$Id$";
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* Expected positive response from server begins like this.
|
* Expected positive response from server begins like this.
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
static const char responseOK[] = "HTTP/1.0 200";
|
static const std::regex responseOK( "HTTP/1.[0-9] 200" );
|
||||||
static const char responseWrongPasswd[] = "HTTP/1.0 401";
|
static const std::regex responseWrongPasswd( "HTTP/1.[0-9] 401" );
|
||||||
static const char responseForbidden[] = "HTTP/1.0 403";
|
static const std::regex responseForbidden( "HTTP/1.[0-9] 403" );
|
||||||
|
static const unsigned int responseLen = Util::strLen( "HTTP/1.0 200" );
|
||||||
|
|
||||||
/* =============================================== local function prototypes */
|
/* =============================================== local function prototypes */
|
||||||
|
|
||||||
|
@ -122,7 +124,7 @@ IceCast2 :: sendLogin ( void ) throw ( Exception )
|
||||||
const int buflen = 1024; // some small buffer size
|
const int buflen = 1024; // some small buffer size
|
||||||
char resp[buflen]; // a little buffer
|
char resp[buflen]; // a little buffer
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
unsigned int lenExpected;
|
std::cmatch cm;
|
||||||
|
|
||||||
if ( !source->isOpen() ) {
|
if ( !source->isOpen() ) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -238,25 +240,24 @@ IceCast2 :: sendLogin ( void ) throw ( Exception )
|
||||||
sink->flush();
|
sink->flush();
|
||||||
|
|
||||||
// read the response, expected response begins with responseOK
|
// read the response, expected response begins with responseOK
|
||||||
lenExpected = Util::strLen( responseOK);
|
if ( (len = source->read( resp, buflen )) < responseLen ) {
|
||||||
if ( (len = source->read( resp, buflen )) < lenExpected ) {
|
|
||||||
return false; // short read, no need to continue
|
return false; // short read, no need to continue
|
||||||
}
|
}
|
||||||
resp[lenExpected] = '\x00'; // end string, truncate to expected length
|
resp[responseLen] = '\x00'; // end string, truncate to expected length
|
||||||
|
|
||||||
reportEvent(5,resp);
|
reportEvent(5,resp);
|
||||||
|
|
||||||
if ( Util::strEq( resp, responseWrongPasswd) ) {
|
if ( std::regex_match( resp, cm, responseWrongPasswd) ) {
|
||||||
throw Exception( __FILE__, __LINE__,
|
throw Exception( __FILE__, __LINE__,
|
||||||
"Icecast2 - wrong password");
|
"Icecast2 - wrong password");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( Util::strEq( resp, responseForbidden) ) {
|
if ( std::regex_match( resp, cm, responseForbidden) ) {
|
||||||
throw Exception( __FILE__, __LINE__,
|
throw Exception( __FILE__, __LINE__,
|
||||||
"Icecast2 - forbidden. Is the mountpoint occupied, or maximum sources reached?");
|
"Icecast2 - forbidden. Is the mountpoint occupied, or maximum sources reached?");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !Util::strEq( resp, responseOK) ) {
|
if ( !std::regex_match( resp, cm, responseOK) ) {
|
||||||
// some unexpected response from server
|
// some unexpected response from server
|
||||||
throw Exception( __FILE__, __LINE__,
|
throw Exception( __FILE__, __LINE__,
|
||||||
"Icecast2 - Unexpected response from server");
|
"Icecast2 - Unexpected response from server");
|
||||||
|
|
Loading…
Reference in New Issue