mirror of
https://github.com/rofafor/vdr-plugin-satip.git
synced 2023-10-10 13:37:42 +02:00
Improved RTSP error checking.
This commit is contained in:
parent
7019b719a5
commit
4d8263e8fd
123
rtsp.c
123
rtsp.c
@ -17,7 +17,10 @@ cSatipRtsp::cSatipRtsp(cSatipTunerIf &tunerP)
|
||||
: tunerM(tunerP),
|
||||
modeM(cmUnicast),
|
||||
handleM(NULL),
|
||||
headerListM(NULL)
|
||||
headerListM(NULL),
|
||||
errorNoMore(""),
|
||||
errorOutOfRange(""),
|
||||
errorCheckSyntax("")
|
||||
{
|
||||
debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
|
||||
Create();
|
||||
@ -61,7 +64,7 @@ size_t cSatipRtsp::HeaderCallback(void *ptrP, size_t sizeP, size_t nmembP, void
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t cSatipRtsp::WriteCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP)
|
||||
size_t cSatipRtsp::DescribeCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP)
|
||||
{
|
||||
cSatipRtsp *obj = reinterpret_cast<cSatipRtsp *>(dataP);
|
||||
size_t len = sizeP * nmembP;
|
||||
@ -73,6 +76,42 @@ size_t cSatipRtsp::WriteCallback(void *ptrP, size_t sizeP, size_t nmembP, void *
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t cSatipRtsp::SetupPlayCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP)
|
||||
{
|
||||
cSatipRtsp *obj = reinterpret_cast<cSatipRtsp *>(dataP);
|
||||
size_t len = sizeP * nmembP;
|
||||
debug16("%s len=%zu", __PRETTY_FUNCTION__, len);
|
||||
|
||||
char *s, *p = (char *)ptrP;
|
||||
char *r = strtok_r(p, "\r\n", &s);
|
||||
|
||||
while (obj && r) {
|
||||
debug16("%s (%zu): %s", __PRETTY_FUNCTION__, len, r);
|
||||
r = skipspace(r);
|
||||
if (strstr(r, "No-More:")) {
|
||||
char *tmp = NULL;
|
||||
if (sscanf(r, "No-More:%m[^;]", &tmp) == 1)
|
||||
obj->SetErrorNoMore(skipspace(tmp));
|
||||
FREE_POINTER(tmp);
|
||||
}
|
||||
else if (strstr(r, "Out-of-Range:")) {
|
||||
char *tmp = NULL;
|
||||
if (sscanf(r, "Out-of-Range:%m[^;]", &tmp) == 1)
|
||||
obj->SetErrorOutOfRange(skipspace(tmp));
|
||||
FREE_POINTER(tmp);
|
||||
}
|
||||
else if (strstr(r, "Check-Syntax:")) {
|
||||
char *tmp = NULL;
|
||||
if (sscanf(r, "Check-Syntax:%m[^;]", &tmp) == 1)
|
||||
obj->SetErrorCheckSyntax(skipspace(tmp));
|
||||
FREE_POINTER(tmp);
|
||||
}
|
||||
r = strtok_r(NULL, "\r\n", &s);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int cSatipRtsp::DebugCallback(CURL *handleP, curl_infotype typeP, char *dataP, size_t sizeP, void *userPtrP)
|
||||
{
|
||||
cSatipRtsp *obj = reinterpret_cast<cSatipRtsp *>(userPtrP);
|
||||
@ -216,10 +255,14 @@ bool cSatipRtsp::Setup(const char *uriP, int rtpPortP, int rtcpPortP)
|
||||
// Set header callback for catching the session and timeout
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_HEADERFUNCTION, cSatipRtsp::HeaderCallback);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEHEADER, this);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEFUNCTION, cSatipRtsp::SetupPlayCallback);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEDATA, this);
|
||||
SATIP_CURL_EASY_PERFORM(handleM);
|
||||
// Session id is now known - disable header parsing
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_HEADERFUNCTION, NULL);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEHEADER, NULL);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEFUNCTION, NULL);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEDATA, NULL);
|
||||
|
||||
result = ValidateLatestResponse(&rc);
|
||||
debug5("%s (%s, %d, %d) Response %ld in %" PRIu64 " ms [device %d]", __PRETTY_FUNCTION__, uriP, rtpPortP, rtcpPortP, rc, processing.Elapsed(), tunerM.GetId());
|
||||
@ -253,7 +296,7 @@ bool cSatipRtsp::Describe(const char *uriP)
|
||||
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_STREAM_URI, uriP);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_DESCRIBE);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEFUNCTION, cSatipRtsp::WriteCallback);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEFUNCTION, cSatipRtsp::DescribeCallback);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEDATA, this);
|
||||
SATIP_CURL_EASY_PERFORM(handleM);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEFUNCTION, NULL);
|
||||
@ -278,7 +321,11 @@ bool cSatipRtsp::Play(const char *uriP)
|
||||
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_STREAM_URI, uriP);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEFUNCTION, cSatipRtsp::SetupPlayCallback);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEDATA, this);
|
||||
SATIP_CURL_EASY_PERFORM(handleM);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEFUNCTION, NULL);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEDATA, NULL);
|
||||
|
||||
result = ValidateLatestResponse(&rc);
|
||||
debug5("%s (%s) Response %ld in %" PRIu64 " ms [device %d]", __PRETTY_FUNCTION__, uriP, rc, processing.Elapsed(), tunerM.GetId());
|
||||
@ -299,7 +346,11 @@ bool cSatipRtsp::Teardown(const char *uriP)
|
||||
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_STREAM_URI, uriP);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_TEARDOWN);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEFUNCTION, cSatipRtsp::SetupPlayCallback);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEDATA, this);
|
||||
SATIP_CURL_EASY_PERFORM(handleM);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEFUNCTION, NULL);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEDATA, NULL);
|
||||
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_CLIENT_CSEQ, 1L);
|
||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_SESSION_ID, NULL);
|
||||
@ -311,24 +362,76 @@ bool cSatipRtsp::Teardown(const char *uriP)
|
||||
return result;
|
||||
}
|
||||
|
||||
void cSatipRtsp::SetErrorNoMore(const char *strP)
|
||||
{
|
||||
debug1("%s (%s) [device %d]", __PRETTY_FUNCTION__, strP, tunerM.GetId());
|
||||
errorNoMore = strP;
|
||||
}
|
||||
|
||||
void cSatipRtsp::SetErrorOutOfRange(const char *strP)
|
||||
{
|
||||
debug1("%s (%s) [device %d]", __PRETTY_FUNCTION__, strP, tunerM.GetId());
|
||||
errorOutOfRange = strP;
|
||||
}
|
||||
|
||||
void cSatipRtsp::SetErrorCheckSyntax(const char *strP)
|
||||
{
|
||||
debug1("%s (%s) [device %d]", __PRETTY_FUNCTION__, strP, tunerM.GetId());
|
||||
errorCheckSyntax = strP;
|
||||
}
|
||||
|
||||
bool cSatipRtsp::ValidateLatestResponse(long *rcP)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (handleM) {
|
||||
char *url = NULL;
|
||||
long rc = 0;
|
||||
CURLcode res = CURLE_OK;
|
||||
SATIP_CURL_EASY_GETINFO(handleM, CURLINFO_RESPONSE_CODE, &rc);
|
||||
if (rc == 200)
|
||||
result = true;
|
||||
else if (rc != 0) {
|
||||
char *url = NULL;
|
||||
SATIP_CURL_EASY_GETINFO(handleM, CURLINFO_EFFECTIVE_URL, &url);
|
||||
error("Detected invalid status code %ld: %s [device %d]", rc, url, tunerM.GetId());
|
||||
}
|
||||
switch (rc) {
|
||||
case 200:
|
||||
result = true;
|
||||
break;
|
||||
case 400:
|
||||
// SETUP PLAY TEARDOWN
|
||||
// The message body of the response may contain the "Check-Syntax:" parameter followed
|
||||
// by the malformed syntax
|
||||
if (!isempty(*errorCheckSyntax)) {
|
||||
SATIP_CURL_EASY_GETINFO(handleM, CURLINFO_EFFECTIVE_URL, &url);
|
||||
error("Check syntax: %s (error code %ld: %s) [device %d]", *errorCheckSyntax, rc, url, tunerM.GetId());
|
||||
break;
|
||||
}
|
||||
case 403:
|
||||
// SETUP PLAY TEARDOWN
|
||||
// The message body of the response may contain the "Out-of-Range:" parameter followed
|
||||
// by a space-separated list of the attribute names that are not understood:
|
||||
// "src" "fe" "freq" "pol" "msys" "mtype" "plts" "ro" "sr" "fec" "pids" "addpids" "delpids" "mcast
|
||||
if (!isempty(*errorOutOfRange)) {
|
||||
SATIP_CURL_EASY_GETINFO(handleM, CURLINFO_EFFECTIVE_URL, &url);
|
||||
error("Out of range: %s (error code %ld: %s) [device %d]", *errorOutOfRange, rc, url, tunerM.GetId());
|
||||
break;
|
||||
}
|
||||
case 503:
|
||||
// SETUP PLAY
|
||||
// The message body of the response may contain the "No-More:" parameter followed
|
||||
// by a space-separated list of the missing ressources: “sessions” "frontends" "pids
|
||||
if (!isempty(*errorNoMore)) {
|
||||
SATIP_CURL_EASY_GETINFO(handleM, CURLINFO_EFFECTIVE_URL, &url);
|
||||
error("No more: %s (error code %ld: %s) [device %d]", *errorNoMore, rc, url, tunerM.GetId());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
SATIP_CURL_EASY_GETINFO(handleM, CURLINFO_EFFECTIVE_URL, &url);
|
||||
error("Detected invalid status code %ld: %s [device %d]", rc, url, tunerM.GetId());
|
||||
break;
|
||||
}
|
||||
if (rcP)
|
||||
*rcP = rc;
|
||||
}
|
||||
errorNoMore = "";
|
||||
errorOutOfRange = "";
|
||||
errorCheckSyntax = "";
|
||||
debug1("%s result=%s [device %d]", __PRETTY_FUNCTION__, result ? "ok" : "failed", tunerM.GetId());
|
||||
|
||||
return result;
|
||||
|
9
rtsp.h
9
rtsp.h
@ -20,7 +20,8 @@
|
||||
class cSatipRtsp {
|
||||
private:
|
||||
static size_t HeaderCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP);
|
||||
static size_t WriteCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP);
|
||||
static size_t DescribeCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP);
|
||||
static size_t SetupPlayCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP);
|
||||
static int DebugCallback(CURL *handleP, curl_infotype typeP, char *dataP, size_t sizeP, void *userPtrP);
|
||||
|
||||
enum {
|
||||
@ -32,9 +33,15 @@ private:
|
||||
eCommunicationMode modeM;
|
||||
CURL *handleM;
|
||||
struct curl_slist *headerListM;
|
||||
cString errorNoMore;
|
||||
cString errorOutOfRange;
|
||||
cString errorCheckSyntax;
|
||||
|
||||
void Create(void);
|
||||
void Destroy(void);
|
||||
void SetErrorNoMore(const char *strP);
|
||||
void SetErrorOutOfRange(const char *strP);
|
||||
void SetErrorCheckSyntax(const char *strP);
|
||||
bool ValidateLatestResponse(long *rcP);
|
||||
|
||||
// to prevent copy constructor and assignment
|
||||
|
Loading…
Reference in New Issue
Block a user