load subscriptions

pull/118/head
orignal 10 years ago
parent 1e87aedbb8
commit 52ee861d3a

@ -177,6 +177,9 @@ namespace client
delete m_Storage;
}
delete m_DefaultSubscription;
for (auto it: m_Subscriptions)
delete it;
}
AddressBookStorage * AddressBook::CreateStorage ()
@ -321,6 +324,26 @@ namespace client
}
}
void AddressBook::LoadSubscriptions ()
{
if (!m_Subscriptions.size ())
{
std::ifstream f (i2p::util::filesystem::GetFullPath ("subscriptions.txt").c_str (), std::ofstream::in); // in text mode
if (f.is_open ())
{
std::string s;
while (!f.eof ())
{
getline(f, s);
if (!s.length()) continue; // skip empty line
m_Subscriptions.push_back (new AddressBookSubscription (*this, s));
}
}
}
else
LogPrint (eLogError, "Subscriptions already loaded");
}
AddressBookSubscription::AddressBookSubscription (AddressBook& book, const std::string& link):
m_Book (book), m_Link (link)
{
@ -349,9 +372,14 @@ namespace client
if (leaseSet)
{
std::stringstream request, response;
// standard header
request << "GET " << u.path_ << " HTTP/1.0\r\nHost: " << u.host_
<< "\r\nAccept: */*\r\n" << "User-Agent: Wget/1.11.4\r\n" << "Connection: close\r\n\r\n";
<< "\r\nAccept: */*\r\n" << "User-Agent: Wget/1.11.4\r\n" << "Connection: close\r\n";
if (m_Etag.length () > 0) // etag
request << HTTP_FIELD_ETAG << ": " << m_Etag << "\r\n";
if (m_LastModified.length () > 0) // if-modfief-since
request << HTTP_FIELD_IF_MODIFIED_SINCE << ": " << m_LastModified << "\r\n";
request << "\r\n"; // end of header
auto stream = i2p::client::context.GetSharedLocalDestination ()->CreateStream (*leaseSet, u.port_);
stream->Send ((uint8_t *)request.str ().c_str (), request.str ().length ());

@ -4,6 +4,7 @@
#include <string.h>
#include <string>
#include <map>
#include <list>
#include <iostream>
#include <mutex>
#include "base64.h"
@ -16,6 +17,10 @@ namespace i2p
namespace client
{
const char DEFAULT_SUBSCRIPTION_ADDRESS[] = "http://udhdrtrcetjm5sxzskjyr5ztpeszydbh4dpl3pl4utgqqw2v4jna.b32.i2p/hosts.txt";
// TODO: move http fields to common http code
const char HTTP_FIELD_ETAG[] = "ETag";
const char HTTP_FIELD_IF_MODIFIED_SINCE[] = "If-Modified-Since";
const char HTTP_FIELD_LAST_MODIFIED[] = "Last-Modified";
class AddressBookStorage // interface for storage
{
@ -50,6 +55,7 @@ namespace client
AddressBookStorage * CreateStorage ();
void LoadHosts ();
void LoadSubscriptions ();
private:
@ -57,6 +63,7 @@ namespace client
std::map<std::string, i2p::data::IdentHash> m_Addresses;
AddressBookStorage * m_Storage;
volatile bool m_IsLoaded, m_IsDownloading;
std::list<AddressBookSubscription *> m_Subscriptions;
AddressBookSubscription * m_DefaultSubscription; // in case if we don't know any addresses yet
};
@ -74,7 +81,7 @@ namespace client
private:
AddressBook& m_Book;
std::string m_Link;
std::string m_Link, m_Etag, m_LastModified;
};
}
}

Loading…
Cancel
Save