1
/* This file is part of Strigi Desktop Search
3
* Copyright (C) 2006 Flavio Castelli <flavio.castelli@gmail.com>
4
* Jos van den Oever <jos@vandenoever.info>
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Library General Public License
17
* along with this library; see the file COPYING.LIB. If not, write to
18
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
22
#include "daemonconfigurator.h"
23
#include "../strigilogging.h"
31
using namespace Strigi;
33
class FindRepository {
38
FindRepository(string repoName) { m_repoName = repoName; }
40
bool operator()(Repository repo) {
41
if (repo.a_name.compare(m_repoName) == 0) {
48
DaemonConfigurator::DaemonConfigurator (const string& confFile)
49
: m_confFile (confFile) {
50
// find the strigi directory
52
string::size_type slashpos = confFile.rfind('/');
53
if (slashpos != string::npos) {
54
strigidir = confFile.substr(0, slashpos);
56
strigidir = getenv("HOME") + string("/.strigi");
60
ifstream f(confFile.c_str(), ios::binary);
64
if (xml.str().length()) {
65
XMLStream stream(xml.str());
68
FindRepository findRepository("localhost");
69
list<Repository>::iterator match = find_if(e_repository.begin(),
73
// entry for localhost repository doesn't exists
74
if (match == e_repository.end()) {
77
r.a_name = "localhost";
80
home.assign(getenv("HOME"));
82
r.a_indexdir = strigidir + "/clucene";
85
r.a_pollingInterval = DEFAULT_POLLING_INTERVAL;
88
p.a_path = home; r.e_path.push_back(p);
89
p.a_path = home + "/.kde"; r.e_path.push_back(p);
90
p.a_path = home + "/.kde4"; r.e_path.push_back(p);
91
p.a_path = home + "/.gnome2"; r.e_path.push_back(p);
92
p.a_path = home + "/.evolution"; r.e_path.push_back(p);
93
p.a_path = home + "/.mozilla"; r.e_path.push_back(p);
94
p.a_path = home + "/.mozilla-thunderbird"; r.e_path.push_back(p);
95
e_repository.push_back(r);
97
// add pattern to ignore hidden directories and hidden files
100
f.a_pattern = ".*.directory/"; // mail box directory
101
e_filters.e_filter.push_back(f);
104
e_filters.e_filter.push_back(f);
106
e_filters.e_filter.push_back(f);
108
STRIGI_LOG_WARNING ("DaemonConfigurator",
109
"created default config for indexed dirs");
114
DaemonConfigurator::setIndexedDirectories ( set<string>& dirs,
115
const string& repositoryName,
117
FindRepository findRepository (repositoryName);
119
list<Repository>::iterator match = find_if (e_repository.begin(),
125
if (match != e_repository.end()) {
128
// create a new repository
130
repo.a_name = repositoryName;
131
e_repository.push_back(repo);
132
return setIndexedDirectories (dirs, repositoryName, merge);
140
for (set<string>::const_iterator iter = dirs.begin(); iter != dirs.end();
144
r->e_path.push_back(p);
148
DaemonConfigurator::getIndexedDirectories(const string& repositoryName) {
151
FindRepository findRepository (repositoryName);
153
list<Repository>::iterator match = find_if (e_repository.begin(),
157
if (match == e_repository.end()) {
158
STRIGI_LOG_WARNING ("DaemonConfigurator.getIndexedDirs",
159
"cannot find repository name: |" + repositoryName + '|');
163
Repository* r = &(*match);
165
for (list<Path>::const_iterator iter = r->e_path.begin();
166
iter != r->e_path.end(); ++iter) {
167
dirs.insert (iter->a_path);
173
DaemonConfigurator::save(const char* file) {
176
f.open(m_confFile.c_str(), ios::binary);
178
f.open(file, ios::binary);
184
DaemonConfigurator::getWriteableIndexType() const {
185
return (e_repository.size()) ?e_repository.begin()->a_type : "";
188
DaemonConfigurator::getWriteableIndexDir() const {
189
return (e_repository.size()) ?e_repository.begin()->a_indexdir : "";
192
DaemonConfigurator::getReadOnlyRepositories() const {
194
list<Repository>::const_iterator i;
195
for (i = e_repository.begin(); i != e_repository.end(); ++i) {
196
if (!i->a_writeable) {
203
DaemonConfigurator::setPollingInterval (unsigned int value,
204
const string& repositoryName) {
205
FindRepository findRepository (repositoryName);
207
list<Repository>::iterator match = find_if (e_repository.begin(),
211
if (match != e_repository.end()) {
212
Repository* r = &(*match);
213
r->a_pollingInterval = value;
215
// create a new repository
217
repo.a_name = repositoryName;
218
repo.a_pollingInterval = value;
219
e_repository.push_back(repo);
224
DaemonConfigurator::getPollingInterval(const string& repositoryName) {
225
FindRepository findRepository (repositoryName);
227
list<Repository>::iterator match = find_if (e_repository.begin(),
233
if (match != e_repository.end()) {
236
// create a new repository
238
repo.a_name = repositoryName;
239
e_repository.push_back(repo);
243
// check minimum polling interval
244
if (r->a_pollingInterval < 5)
246
r->a_pollingInterval = DEFAULT_POLLING_INTERVAL;
247
return DEFAULT_POLLING_INTERVAL;
249
return r->a_pollingInterval;
253
DaemonConfigurator::loadFilteringRules(AnalyzerConfiguration& config) {
254
vector<pair<bool,string> > filters;
255
list<Filter>::const_iterator i;
256
for (i = e_filters.e_filter.begin(); i != e_filters.e_filter.end(); ++i) {
257
filters.push_back(make_pair<bool,string>(i->a_include, i->a_pattern));
259
config.setFilters(filters);
262
DaemonConfigurator::saveFilteringRules(const vector<pair<bool,string> >& f) {
263
e_filters.e_filter.clear();
264
vector<pair<bool,string> >::const_iterator i;
265
for (i = f.begin(); i != f.end(); ++i) {
267
f.a_include = i->first;
268
f.a_pattern = i->second;
269
e_filters.e_filter.push_back(f);