From eea0aa33bd8094e761e30b8b9a78fa744628598f Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Sat, 29 Nov 2014 15:37:21 +0200 Subject: [PATCH] Added cSatipDiscoverIf(). --- discover.c | 19 +++++++------ discover.h | 8 ++++-- discoverif.h | 22 +++++++++++++++ msearch.c | 77 +++++++++++++++++++++++++++------------------------- msearch.h | 4 ++- rtcp.c | 16 +++++------ rtp.c | 2 +- 7 files changed, 90 insertions(+), 58 deletions(-) create mode 100644 discoverif.h diff --git a/discover.c b/discover.c index f8fbd82..c4c5293 100644 --- a/discover.c +++ b/discover.c @@ -119,7 +119,7 @@ int cSatipDiscover::DebugCallback(CURL *handleP, curl_infotype typeP, char *data cSatipDiscover::cSatipDiscover() : cThread("SAT>IP discover"), mutexM(), - msearchM(), + msearchM(*this), probeUrlListM(), handleM(curl_easy_init()), sleepM(), @@ -190,14 +190,6 @@ void cSatipDiscover::Action(void) debug("cSatipDiscover::%s(): exiting", __FUNCTION__); } -void cSatipDiscover::Probe(const char *urlP) -{ - debug("cSatipDiscover::%s(%s)", __FUNCTION__, urlP); - cMutexLock MutexLock(&mutexM); - probeUrlListM.Insert(strdup(urlP)); - sleepM.Signal(); -} - void cSatipDiscover::Fetch(const char *urlP) { debug("cSatipDiscover::%s(%s)", __FUNCTION__, urlP); @@ -312,3 +304,12 @@ int cSatipDiscover::NumProvidedSystems(void) cMutexLock MutexLock(&mutexM); return serversM.NumProvidedSystems(); } + +void cSatipDiscover::SetUrl(const char *urlP) +{ + //debug("cSatipDiscover::%s(%s)", __FUNCTION__, urlP); + mutexM.Lock(); + probeUrlListM.Insert(strdup(urlP)); + mutexM.Unlock(); + sleepM.Signal(); +} diff --git a/discover.h b/discover.h index 601676f..74e72b5 100644 --- a/discover.h +++ b/discover.h @@ -13,6 +13,7 @@ #include #include +#include "discoverif.h" #include "msearch.h" #include "server.h" #include "socket.h" @@ -35,7 +36,7 @@ public: class cSatipDiscoverServers : public cList { }; -class cSatipDiscover : public cThread { +class cSatipDiscover : public cThread, public cSatipDiscoverIf { private: enum { eSleepTimeoutMs = 500, // in milliseconds @@ -71,7 +72,6 @@ public: static bool Initialize(cSatipDiscoverServers *serversP); static void Destroy(void); virtual ~cSatipDiscover(); - void Probe(const char *urlP); void TriggerScan(void) { probeIntervalM.Set(0); } int GetServerCount(void); cSatipServer *GetServer(int sourceP, int transponderP = 0, int systemP = -1); @@ -82,6 +82,10 @@ public: void UseServer(cSatipServer *serverP, bool onOffP); cString GetServerList(void); int NumProvidedSystems(void); + + // for internal discover interface +public: + virtual void SetUrl(const char *urlP); }; #endif // __SATIP_DISCOVER_H diff --git a/discoverif.h b/discoverif.h new file mode 100644 index 0000000..b6218c5 --- /dev/null +++ b/discoverif.h @@ -0,0 +1,22 @@ +/* + * discoverif.h: SAT>IP plugin for the Video Disk Recorder + * + * See the README file for copyright information and how to reach the author. + * + */ + +#ifndef __SATIP_DISCOVERIF_H +#define __SATIP_DISCOVERIF_H + +class cSatipDiscoverIf { +public: + cSatipDiscoverIf() {} + virtual ~cSatipDiscoverIf() {} + virtual void SetUrl(const char *urlP) = 0; + +private: + cSatipDiscoverIf(const cSatipDiscoverIf&); + cSatipDiscoverIf& operator=(const cSatipDiscoverIf&); +}; + +#endif // __SATIP_DISCOVERIF_H diff --git a/msearch.c b/msearch.c index 6aa920c..4ebfa15 100644 --- a/msearch.c +++ b/msearch.c @@ -17,8 +17,9 @@ const char *cSatipMsearch::bcastMessageS = "M-SEARCH * HTTP/1.1\r\n" "ST: urn:ses-com:device:SatIPServer:1\r\n" \ "MX: 2\r\n\r\n"; -cSatipMsearch::cSatipMsearch(void) -: bufferLenM(eProbeBufferSize), +cSatipMsearch::cSatipMsearch(cSatipDiscoverIf &discoverP) +: discoverM(discoverP), + bufferLenM(eProbeBufferSize), bufferM(MALLOC(unsigned char, bufferLenM)), registeredM(false) { @@ -53,43 +54,45 @@ void cSatipMsearch::Process(void) { //debug("cSatipMsearch::%s()", __FUNCTION__); if (bufferM) { - int length = Read(bufferM, bufferLenM); - if (length > 0) { - bufferM[min(length, int(bufferLenM - 1))] = 0; - //debug("cSatipMsearch::%s(): len=%d buf=%s", __FUNCTION__, length, bufferM); - bool status = false, valid = false; - char *s, *p = reinterpret_cast(bufferM), *location = NULL; - char *r = strtok_r(p, "\r\n", &s); - while (r) { - //debug("cSatipMsearch::%s(): %s", __FUNCTION__, r); - // Check the status code - // HTTP/1.1 200 OK - if (!status && startswith(r, "HTTP/1.1 200 OK")) - status = true; - if (status) { - // Check the location data - // LOCATION: http://192.168.0.115:8888/octonet.xml - if (startswith(r, "LOCATION:")) { - location = compactspace(r + 9); - debug("cSatipMsearch::%s(): location='%s'", __FUNCTION__, location); - } - // Check the source type - // ST: urn:ses-com:device:SatIPServer:1 - else if (startswith(r, "ST:")) { - char *st = compactspace(r + 3); - if (strstr(st, "urn:ses-com:device:SatIPServer:1")) - valid = true; - debug("cSatipMsearch::%s(): st='%s'", __FUNCTION__, st); - } - // Check whether all the required data is found - if (valid && !isempty(location)) { - cSatipDiscover::GetInstance()->Probe(location); - break; + int length; + while ((length = Read(bufferM, bufferLenM)) > 0) { + bufferM[min(length, int(bufferLenM - 1))] = 0; + //debug("cSatipMsearch::%s(): len=%d buf=%s", __FUNCTION__, length, bufferM); + bool status = false, valid = false; + char *s, *p = reinterpret_cast(bufferM), *location = NULL; + char *r = strtok_r(p, "\r\n", &s); + while (r) { + //debug("cSatipMsearch::%s(): %s", __FUNCTION__, r); + // Check the status code + // HTTP/1.1 200 OK + if (!status && startswith(r, "HTTP/1.1 200 OK")) + status = true; + if (status) { + // Check the location data + // LOCATION: http://192.168.0.115:8888/octonet.xml + if (startswith(r, "LOCATION:")) { + location = compactspace(r + 9); + debug("cSatipMsearch::%s(): location='%s'", __FUNCTION__, location); + } + // Check the source type + // ST: urn:ses-com:device:SatIPServer:1 + else if (startswith(r, "ST:")) { + char *st = compactspace(r + 3); + if (strstr(st, "urn:ses-com:device:SatIPServer:1")) + valid = true; + debug("cSatipMsearch::%s(): st='%s'", __FUNCTION__, st); + } + // Check whether all the required data is found + if (valid && !isempty(location)) { + discoverM.SetUrl(location); + break; + } } + r = strtok_r(NULL, "\r\n", &s); } - r = strtok_r(NULL, "\r\n", &s); - } - } + } + if (errno != EAGAIN && errno != EWOULDBLOCK) + error("Error %d reading in %s", errno, *ToString()); } } diff --git a/msearch.h b/msearch.h index 87e730f..b27a008 100644 --- a/msearch.h +++ b/msearch.h @@ -8,6 +8,7 @@ #ifndef __SATIP_MSEARCH_H_ #define __SATIP_MSEARCH_H_ +#include "discoverif.h" #include "socket.h" #include "pollerif.h" @@ -19,12 +20,13 @@ private: }; static const char *bcastAddressS; static const char *bcastMessageS; + cSatipDiscoverIf &discoverM; unsigned int bufferLenM; unsigned char *bufferM; bool registeredM; public: - cSatipMsearch(void); + cSatipMsearch(cSatipDiscoverIf &discoverP); virtual ~cSatipMsearch(); void Probe(void); diff --git a/rtcp.c b/rtcp.c index e3f3f79..2a636ad 100644 --- a/rtcp.c +++ b/rtcp.c @@ -81,14 +81,14 @@ void cSatipRtcp::Process(void) { //debug("cSatipRtcp::%s() [device %d]", __FUNCTION__, tunerM.GetId()); if (bufferM) { - int length; - while ((length = Read(bufferM, bufferLenM)) > 0) { - int offset = GetApplicationOffset(&length); - if (offset >= 0) - tunerM.ProcessApplicationData(bufferM + offset, length); - } - if (errno != EAGAIN && errno != EWOULDBLOCK) - error("Error %d reading from RTCP socket [device %d]", errno, tunerM.GetId()); + int length; + while ((length = Read(bufferM, bufferLenM)) > 0) { + int offset = GetApplicationOffset(&length); + if (offset >= 0) + tunerM.ProcessApplicationData(bufferM + offset, length); + } + if (errno != EAGAIN && errno != EWOULDBLOCK) + error("Error %d reading in %s", errno, *ToString()); } } diff --git a/rtp.c b/rtp.c index d3a51b5..43e0b45 100644 --- a/rtp.c +++ b/rtp.c @@ -118,7 +118,7 @@ void cSatipRtp::Process(void) tunerM.ProcessVideoData(bufferM + headerlen, length - headerlen); } if (errno != EAGAIN && errno != EWOULDBLOCK) - error("Error %d reading from RTP socket [device %d]", errno, tunerM.GetId()); + error("Error %d reading in %s", errno, *ToString()); } }