|
|
|
@ -262,3 +262,95 @@ int FBSmartHome::CloseSIDFile() {
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* retrieve the device list from the fritzbox
|
|
|
|
|
*/
|
|
|
|
|
std::list<FBSmartHomeDevice> *FBSmartHome::GetDevices() {
|
|
|
|
|
std::list<FBSmartHomeDevice> *devlist = NULL;
|
|
|
|
|
FBSmartHomeDevice smd;
|
|
|
|
|
xmlDocPtr xmldoc;
|
|
|
|
|
xmlNodePtr xmlnode;
|
|
|
|
|
xmlAttr *xmlattr;
|
|
|
|
|
|
|
|
|
|
int len;
|
|
|
|
|
|
|
|
|
|
// retrieve data
|
|
|
|
|
len = tcp.WebGetFile(hostname+"/webservices/homeautoswitch.lua?sid="+SID+"&switchcmd=getdevicelistinfos", inbuffer, FB_BUFFER, NULL);
|
|
|
|
|
if (len > FB_BUFFER) len = FB_BUFFER;
|
|
|
|
|
else if (len < 0) {
|
|
|
|
|
fprintf (stderr, "%s:%d Error getting challenge from Fritzbox\n", __FILE__, __LINE__);
|
|
|
|
|
errno = EAI_FAIL;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
inbuffer[len] = '\0';
|
|
|
|
|
XMLPrepare(inbuffer, len, &xmldoc, &xmlnode);
|
|
|
|
|
printf ("*********************************************\n%s\n*********************************\n", inbuffer);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// parse for SID and Challange
|
|
|
|
|
while (xmlnode) {
|
|
|
|
|
if ((!xmlStrcmp(xmlnode->name, (const xmlChar *)"devicelist"))){
|
|
|
|
|
xmlNodePtr xmlchild = xmlnode->xmlChildrenNode;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// read each device details
|
|
|
|
|
//
|
|
|
|
|
while (xmlchild) {
|
|
|
|
|
printf ("Name:%s\n", xmlchild->name);
|
|
|
|
|
//
|
|
|
|
|
// read attributes
|
|
|
|
|
xmlattr = xmlchild->properties;
|
|
|
|
|
while (xmlattr) {
|
|
|
|
|
printf (" %s:%s ", xmlattr->name, xmlNodeListGetString(xmldoc, xmlattr->children, 1));
|
|
|
|
|
xmlattr = xmlattr->next;
|
|
|
|
|
}
|
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
|
|
// go thought all the subchildreen
|
|
|
|
|
xmlNodePtr xmlsubchild = xmlchild->children;
|
|
|
|
|
while (xmlsubchild) {
|
|
|
|
|
printf (" %s,%s ", xmlsubchild->name,
|
|
|
|
|
(char *)xmlNodeListGetString(xmldoc, xmlsubchild->children, 1));
|
|
|
|
|
xmlattr = xmlsubchild->properties;
|
|
|
|
|
while (xmlattr) {
|
|
|
|
|
printf (" %s:%s ", xmlattr->name, xmlNodeListGetString(xmldoc, xmlattr->children, 1));
|
|
|
|
|
xmlattr = xmlattr->next;
|
|
|
|
|
}
|
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
|
|
xmlNodePtr xmlsubchild2 = xmlsubchild->children;
|
|
|
|
|
while (xmlsubchild2) {
|
|
|
|
|
printf (" %s,%s ", xmlsubchild2->name,
|
|
|
|
|
(char *)xmlNodeListGetString(xmldoc, xmlsubchild2->children, 1));
|
|
|
|
|
xmlattr = xmlsubchild2->properties;
|
|
|
|
|
while (xmlattr) {
|
|
|
|
|
printf (" %s:%s ", xmlattr->name, xmlNodeListGetString(xmldoc, xmlattr->children, 1));
|
|
|
|
|
xmlattr = xmlattr->next;
|
|
|
|
|
}
|
|
|
|
|
printf ("\n");
|
|
|
|
|
xmlsubchild2 = xmlsubchild2->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xmlsubchild = xmlsubchild->next;
|
|
|
|
|
}
|
|
|
|
|
printf ("\n");
|
|
|
|
|
xmlchild = xmlchild->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
xmlnode = xmlnode->next;
|
|
|
|
|
}
|
|
|
|
|
xmlFreeDoc(xmldoc);
|
|
|
|
|
|
|
|
|
|
if (SID.compare("0000000000000000") == 0) {
|
|
|
|
|
hostname = "";
|
|
|
|
|
errno = ENOTCONN;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return devlist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|