1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
// Author: Jose M. Vidal
// $Id: channel.H,v 1.3 2002/04/02 19:02:22 jmvidal Exp $
// This code is copyright of Jose M. Vidal and released under
// the GNU General Public License
//
#ifndef CHANNEL_H
#define CHANNEL_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string>
#include <vector>
#include "reference.H"
#include "iwebstream.H"
class channel {
vector<reference> items;
string name;
string url;
string backupFile; //to write the channel contents, to read the channel from if url fails.
bool read; //true if we have readChannel() already
//the data below we read from the channel file after fetching it
string title;
string siteUrl;
string description;
string image; //also a url, to an image
string language;
string imageTitle;
string imageUrl;
string imageLink;
// proxy stufff
string proxy_host;
int proxy_port;
string proxy_user;
string proxy_password;
bool readStream(iwebstream & is);
void readImage();
public:
channel (const string & proxy_host, int proxy_port, const string & proxy_user, const string & proxy_password)
: name(""), url(""), backupFile(""), read(false), title(""), siteUrl(""),
description(""), language(""), imageTitle(""), imageUrl(""), imageLink(""),
proxy_host(proxy_host), proxy_port(proxy_port), proxy_user(proxy_user), proxy_password(proxy_password) {};
channel (const string & n, const string & u, const string & f, const string & proxy_host,
int proxy_port, const string & proxy_user, const string & proxy_password)
: name(n), url(u), backupFile(f), read(false), title(""), siteUrl(""), description(""),
language(""), imageTitle(""), imageUrl(""), imageLink(""),
proxy_host(proxy_host), proxy_port(proxy_port), proxy_user(proxy_user), proxy_password(proxy_password) {};
//this is the same as default:
// channel (const channel & c) : name(c.name), url(c.url), backupFile(c.backupFile),
// read(c.read), title(c.title), siteUrl(c.siteUrl), description(c.description),
// language(c.language), imageTitle(c.imageTitle), imageUrl(c.imageUrl),
// imageLink(c.imageLink) {};
vector<reference> getItems(){
return items;
};
string getName(){
return name;
}
//returns true if successful, false if we had to read it from backupFile;
bool readChannel();
void increaseHits(const string & url, int x);
};
class channelContainer {
vector<channel> channels;
public:
channelContainer() {};
void addNewChannel(const string & name, const string & url, const string & backupFile,
const string & proxy_host, int proxy_port, const string & proxy_user, const string & proxy_password) {
if (nameExists(name)) //exit silently
return;
channel c(name, url, backupFile, proxy_host, proxy_port, proxy_user, proxy_password);
c.readChannel();
channels.push_back(c);
}
bool nameExists(const string &name) {
channel c("", 0, "", "");
return getChannel (name, c);
}
bool getChannel (const string & name, channel & c) {
for (vector<channel>::iterator i = channels.begin(); i != channels.end(); ++i) {
channel &r = *i;
if (r.getName() == name) {
c = r;
return true;
}
}
return false;
}
void increaseHits(const string & url, int x){
for (vector<channel>::iterator i = channels.begin(); i != channels.end(); ++i) {
channel &r = *i;
r.increaseHits(url, x);
}
};
};
#endif
|