/** * \fn UPNPScanner::replyFinished(void) * Validates network responses against known requests and parses expected * responses for the required data. */ void UPNPScanner::replyFinished(QNetworkReply *reply) { if (!reply) return; QUrl url = reply->url(); bool valid = reply->error() == QNetworkReply::NoError; if (!valid) { LOG(VB_UPNP, LOG_ERR, LOC + QString("Network request for '%1' returned error '%2'") .arg(url.toString()).arg(reply->errorString())); } bool description = false; bool browse = false; m_lock.lock(); if (m_descriptionRequests.contains(url, reply)) { m_descriptionRequests.remove(url, reply); description = true; } else if (m_browseRequests.contains(url, reply)) { m_browseRequests.remove(url, reply); browse = true; } m_lock.unlock(); if (browse && valid) { ParseBrowse(url, reply); // a complete scan is event driven, so trigger the next browse BrowseNextContainer(); } else if (description) { if (!valid || (valid && !ParseDescription(url, reply))) { // if there will be no more attempts, update the logs CheckFailure(url); // try again ScheduleUpdate(); } } else LOG(VB_UPNP, LOG_ERR, LOC + "Received unknown reply"); reply->deleteLater(); }
void ImageMetadata::Init(const std::string& name, int width, int height) { SYSTEM_STREAM << "Begin to init metadata for " << name << std::endl; png_byte pngsig[PNGSIGSIZE]; width_ = width; height_ = height; std::ifstream source; source.open(name, std::fstream::binary); if (source.fail()) { SYSTEM_STREAM << "ERROR: Fail to open smth" << std::endl; return; } source.read(reinterpret_cast<char*>(pngsig), PNGSIGSIZE); if (source.fail()) { SYSTEM_STREAM << "ERROR: Fail to read smth" << std::endl; SYSTEM_STREAM << source.bad() << " " << source.fail() << " " << source.eof() << std::endl; kv_abort(); return; } int is_png = png_sig_cmp(pngsig, 0, PNGSIGSIZE); if (is_png) { SYSTEM_STREAM << "ERROR: Data is not valid PNG-data: " << is_png << std::endl; InitWithoutMetadata(); return; } png_structp pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!pngPtr) { SYSTEM_STREAM << "ERROR: Couldn't initialize png read struct" << std::endl; return; } png_infop infoPtr = png_create_info_struct(pngPtr); if (!infoPtr) { std::cerr << "ERROR: Couldn't initialize png info struct" << std::endl; png_destroy_read_struct(&pngPtr, static_cast<png_infopp>(0), static_cast<png_infopp>(0)); return; } png_set_read_fn(pngPtr, static_cast<png_voidp>(&source), userReadData); png_set_sig_bytes(pngPtr, PNGSIGSIZE); png_read_info(pngPtr, infoPtr); png_get_IHDR(pngPtr, infoPtr, &total_width_, &total_height_, 0, 0, 0, 0, 0); png_textp text_ptr; int num_text; if (png_get_text(pngPtr, infoPtr, &text_ptr, &num_text) > 0) { for (int i = 0; i < num_text; ++i) { /* SYSTEM_STREAM << "BEGIN KEY " << i << std::endl; SYSTEM_STREAM << text_ptr[i].key << std::endl; SYSTEM_STREAM << "END KEY " << i << std::endl; SYSTEM_STREAM << "BEGIN TEXT " << i << std::endl; SYSTEM_STREAM << text_ptr[i].text << std::endl; SYSTEM_STREAM << "END TEXT " << i << std::endl; */ std::string string_key = std::string(text_ptr[i].key); if (string_key == "Description") { std::stringstream string_text; string_text << std::string(text_ptr[i].text); ParseDescription(string_text); break; } } } //SDL_Delay(100000); png_destroy_read_struct(&pngPtr, &infoPtr, static_cast<png_infopp>(0)); source.close(); SYSTEM_STREAM << "End load metadata for " << name << std::endl; if (!Valid()) { InitWithoutMetadata(); } }