static int watchSSDP( tr_upnp_device_t ** devices, int fd ) { /* XXX what if we get a huge SSDP packet? */ char buf[512]; int len; tr_http_header_t hdr[] = { /* first one must be type and second must be subtype */ { NULL, NULL, 0 }, { "NTS", NULL, 0 }, /* XXX should probably look at this { "Cache-control", NULL, 0 }, */ { "Location", NULL, 0 }, { "USN", NULL, 0 }, { NULL, NULL, 0 } }; enum { OFF_TYPE = 0, OFF_SUBTYPE, OFF_LOC, OFF_ID }; int ret; if( 0 > fd ) { return 0; } ret = 0; for(;;) { len = sizeof( buf ); switch( recvSSDP( fd, buf, &len ) ) { case TR_WAIT: return ret; case TR_ERROR: return 1; case TR_OK: ret = 1; if( parseSSDP( buf, len, hdr ) && NULL != hdr[OFF_LOC].data && NULL != hdr[OFF_ID].data ) { deviceAdd( devices, hdr[OFF_ID].data, hdr[OFF_ID].len, hdr[OFF_LOC].data, hdr[OFF_LOC].len ); } } } }
void DeviceManager::deviceLoadConfigXml(std::string filename) { XMLNode xMainNode = XMLNode::openFileHelper(filename.c_str(), "deviceManager"); XMLNode xNode = xMainNode.getChildNode("sendDevices"); int nChild = xNode.nChildNode(); std::map<std::string, std::string> deviceParameters; for (int i = 0; i < nChild; i++) { XMLNode deviceNode = xNode.getChildNode(i); int nAttr = deviceNode.nAttribute(); for (int j = 1; j < nAttr; j++) { deviceParameters[deviceNode.getAttributeName(j)] = deviceNode.getAttributeValue(j); } deviceAdd(deviceNode.getAttributeValue(0), deviceNode.getName(), &deviceParameters); deviceParameters.clear(); } }