// -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- // Author: Jose M. Vidal // $Id: channel.C,v 1.10 2003/05/11 18:58:50 jmvidal Exp $ // This code is copyright of Jose M. Vidal and released under // the GNU General Public License #include "channel.H" #include "XMLParser.H" //defined in reference.C extern string trim(const string & s); bool channel::readChannel() { if (read && title == "") return false; //we failed before, dont try again else if (read) return true; //already read it OK. read = true; //we will try to read it. cout << "Reading channel " << name << endl; iwebstream *istream_ptr = 0; if ( proxy_host != "" ) { istream_ptr = new iwebstream(url, proxy_host, proxy_port, proxy_user, proxy_password); } else { istream_ptr = new iwebstream(url); } if (*istream_ptr == 0) { //could not read url, try backup file cerr << "Could not read channel=" << name << ", trying backup file" << endl; iwebstream ifs2(backupFile); //backup file could also be a url! if (ifs2 == 0) { cerr << "Could not read backup file=" << backupFile << endl; return false; } referenceTree * inputTree = new referenceTree(); RSSParser rssp(inputTree); rssp.parse(*istream_ptr); items = inputTree->getContents(); } else { //read url OK. referenceTree * inputTree = new referenceTree(); RSSParser rssp(inputTree); rssp.parse(*istream_ptr); items = inputTree->getContents(); } delete istream_ptr; return true; } //not used, dont know if it works. void channel::readImage() { if (imageLink != "") { iwebstream image(imageLink); if (image != 0){ string filename = backupFile + "-image"; ofstream of(filename.c_str()); for (char c = image.get(); !image.eof(); c =image.get()) { of << c; } of.close(); } } } /** Parse an RSS channel. This should go away soon and be replaced with XMLParser. */ bool channel::readStream(iwebstream & is) { const string channelT = "::iterator i = items.begin(); i!= items.end(); ++i){ if ((*i).url == url) (*i).hits+= x; }; }