mirror of
https://github.com/rofafor/vdr-plugin-satip.git
synced 2023-10-10 13:37:42 +02:00
Fixed CURL buffer size for discovery.
This commit is contained in:
parent
748ea15d1d
commit
942d3a936e
69
discover.c
69
discover.c
@ -54,37 +54,8 @@ size_t cSatipDiscover::WriteCallback(char *ptrP, size_t sizeP, size_t nmembP, vo
|
|||||||
debug16("%s len=%zu", __PRETTY_FUNCTION__, len);
|
debug16("%s len=%zu", __PRETTY_FUNCTION__, len);
|
||||||
|
|
||||||
if (obj) {
|
if (obj) {
|
||||||
CURLcode res = CURLE_OK;
|
char *s = strndup(ptrP, len);
|
||||||
const char *desc = NULL, *model = NULL, *addr = NULL;
|
obj->deviceInfoM = cString::sprintf("%s%s", *obj->deviceInfoM, s ? s : "");
|
||||||
SATIP_CURL_EASY_GETINFO(obj->handleM, CURLINFO_PRIMARY_IP, &addr);
|
|
||||||
#ifdef USE_TINYXML
|
|
||||||
TiXmlDocument doc;
|
|
||||||
char *xml = MALLOC(char, len + 1);
|
|
||||||
memcpy(xml, ptrP, len);
|
|
||||||
*(xml + len) = 0;
|
|
||||||
doc.Parse((const char *)xml);
|
|
||||||
TiXmlHandle docHandle(&doc);
|
|
||||||
TiXmlElement *descElement = docHandle.FirstChild("root").FirstChild("device").FirstChild("friendlyName").ToElement();
|
|
||||||
if (descElement)
|
|
||||||
desc = descElement->GetText() ? descElement->GetText() : "MyBrokenHardware";
|
|
||||||
TiXmlElement *modelElement = docHandle.FirstChild("root").FirstChild("device").FirstChild("satip:X_SATIPCAP").ToElement();
|
|
||||||
if (modelElement)
|
|
||||||
model = modelElement->GetText() ? modelElement->GetText() : "DVBS2-1";
|
|
||||||
obj->AddServer(addr, model, desc);
|
|
||||||
FREE_POINTER(xml);
|
|
||||||
#else
|
|
||||||
pugi::xml_document doc;
|
|
||||||
pugi::xml_parse_result result = doc.load_buffer(ptrP, len);
|
|
||||||
if (result) {
|
|
||||||
pugi::xml_node descNode = doc.first_element_by_path("root/device/friendlyName");
|
|
||||||
if (descNode)
|
|
||||||
desc = descNode.text().as_string("MyBrokenHardware");
|
|
||||||
pugi::xml_node modelNode = doc.first_element_by_path("root/device/satip:X_SATIPCAP");
|
|
||||||
if (modelNode)
|
|
||||||
model = modelNode.text().as_string("DVBS2-1");
|
|
||||||
}
|
|
||||||
obj->AddServer(addr, model, desc);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
@ -122,6 +93,7 @@ int cSatipDiscover::DebugCallback(CURL *handleP, curl_infotype typeP, char *data
|
|||||||
cSatipDiscover::cSatipDiscover()
|
cSatipDiscover::cSatipDiscover()
|
||||||
: cThread("SATIP discover"),
|
: cThread("SATIP discover"),
|
||||||
mutexM(),
|
mutexM(),
|
||||||
|
deviceInfoM(""),
|
||||||
msearchM(*this),
|
msearchM(*this),
|
||||||
probeUrlListM(),
|
probeUrlListM(),
|
||||||
handleM(curl_easy_init()),
|
handleM(curl_easy_init()),
|
||||||
@ -197,6 +169,7 @@ void cSatipDiscover::Fetch(const char *urlP)
|
|||||||
{
|
{
|
||||||
debug1("%s (%s)", __PRETTY_FUNCTION__, urlP);
|
debug1("%s (%s)", __PRETTY_FUNCTION__, urlP);
|
||||||
if (handleM && !isempty(urlP)) {
|
if (handleM && !isempty(urlP)) {
|
||||||
|
const char *addr = NULL;
|
||||||
long rc = 0;
|
long rc = 0;
|
||||||
CURLcode res = CURLE_OK;
|
CURLcode res = CURLE_OK;
|
||||||
|
|
||||||
@ -224,13 +197,45 @@ void cSatipDiscover::Fetch(const char *urlP)
|
|||||||
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_URL, urlP);
|
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_URL, urlP);
|
||||||
|
|
||||||
// Fetch the data
|
// Fetch the data
|
||||||
|
deviceInfoM = "";
|
||||||
SATIP_CURL_EASY_PERFORM(handleM);
|
SATIP_CURL_EASY_PERFORM(handleM);
|
||||||
SATIP_CURL_EASY_GETINFO(handleM, CURLINFO_RESPONSE_CODE, &rc);
|
SATIP_CURL_EASY_GETINFO(handleM, CURLINFO_RESPONSE_CODE, &rc);
|
||||||
if (rc != 200)
|
SATIP_CURL_EASY_GETINFO(handleM, CURLINFO_PRIMARY_IP, &addr);
|
||||||
|
if (rc == 200)
|
||||||
|
ParseDeviceInfo(addr);
|
||||||
|
else
|
||||||
error("Discovery detected invalid status code: %ld", rc);
|
error("Discovery detected invalid status code: %ld", rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cSatipDiscover::ParseDeviceInfo(const char *addrP)
|
||||||
|
{
|
||||||
|
debug1("%s (%s)", __PRETTY_FUNCTION__, addrP);
|
||||||
|
const char *desc = NULL, *model = NULL;
|
||||||
|
#ifdef USE_TINYXML
|
||||||
|
TiXmlDocument doc;
|
||||||
|
doc.Parse(*deviceInfoM);
|
||||||
|
TiXmlHandle docHandle(&doc);
|
||||||
|
TiXmlElement *descElement = docHandle.FirstChild("root").FirstChild("device").FirstChild("friendlyName").ToElement();
|
||||||
|
if (descElement)
|
||||||
|
desc = descElement->GetText() ? descElement->GetText() : "MyBrokenHardware";
|
||||||
|
TiXmlElement *modelElement = docHandle.FirstChild("root").FirstChild("device").FirstChild("satip:X_SATIPCAP").ToElement();
|
||||||
|
if (modelElement)
|
||||||
|
model = modelElement->GetText() ? modelElement->GetText() : "DVBS2-1";
|
||||||
|
#else
|
||||||
|
pugi::xml_document doc;
|
||||||
|
if (doc.load_buffer(*deviceInfoM, strlen(*deviceInfoM))) {
|
||||||
|
pugi::xml_node descNode = doc.first_element_by_path("root/device/friendlyName");
|
||||||
|
if (descNode)
|
||||||
|
desc = descNode.text().as_string("MyBrokenHardware");
|
||||||
|
pugi::xml_node modelNode = doc.first_element_by_path("root/device/satip:X_SATIPCAP");
|
||||||
|
if (modelNode)
|
||||||
|
model = modelNode.text().as_string("DVBS2-1");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
AddServer(addrP, model, desc);
|
||||||
|
}
|
||||||
|
|
||||||
void cSatipDiscover::AddServer(const char *addrP, const char *modelP, const char * descP)
|
void cSatipDiscover::AddServer(const char *addrP, const char *modelP, const char * descP)
|
||||||
{
|
{
|
||||||
debug1("%s (%s, %s, %s)", __PRETTY_FUNCTION__, addrP, modelP, descP);
|
debug1("%s (%s, %s, %s)", __PRETTY_FUNCTION__, addrP, modelP, descP);
|
||||||
|
@ -48,6 +48,7 @@ private:
|
|||||||
static size_t WriteCallback(char *ptrP, size_t sizeP, size_t nmembP, void *dataP);
|
static size_t WriteCallback(char *ptrP, size_t sizeP, size_t nmembP, void *dataP);
|
||||||
static int DebugCallback(CURL *handleP, curl_infotype typeP, char *dataP, size_t sizeP, void *userPtrP);
|
static int DebugCallback(CURL *handleP, curl_infotype typeP, char *dataP, size_t sizeP, void *userPtrP);
|
||||||
cMutex mutexM;
|
cMutex mutexM;
|
||||||
|
cString deviceInfoM;
|
||||||
cSatipMsearch msearchM;
|
cSatipMsearch msearchM;
|
||||||
cStringList probeUrlListM;
|
cStringList probeUrlListM;
|
||||||
CURL *handleM;
|
CURL *handleM;
|
||||||
@ -56,6 +57,7 @@ private:
|
|||||||
cSatipServers serversM;
|
cSatipServers serversM;
|
||||||
void Activate(void);
|
void Activate(void);
|
||||||
void Deactivate(void);
|
void Deactivate(void);
|
||||||
|
void ParseDeviceInfo(const char *addrP);
|
||||||
void AddServer(const char *addrP, const char *modelP, const char *descP);
|
void AddServer(const char *addrP, const char *modelP, const char *descP);
|
||||||
void Fetch(const char *urlP);
|
void Fetch(const char *urlP);
|
||||||
// constructor
|
// constructor
|
||||||
|
Loading…
Reference in New Issue
Block a user