1
/******************************************************************************
2
* swmgr.cpp - implementaion of class SWMgr used to interact with an install
3
* base of sword modules.
5
* $Id: swmgr.cpp,v 1.96 2003/12/05 21:44:33 scribe Exp $
7
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
8
* CrossWire Bible Society
10
* Tempe, AZ 85280-2528
12
* This program is free software; you can redistribute it and/or modify it
13
* under the terms of the GNU General Public License as published by the
14
* Free Software Foundation version 2.
16
* This program is distributed in the hope that it will be useful, but
17
* WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* General Public License for more details.
41
#include <rawgenbook.h>
48
#include <thmlplain.h>
49
#include <osisplain.h>
50
#include <gbfstrongs.h>
51
#include <gbffootnotes.h>
52
#include <gbfheadings.h>
53
#include <gbfredletterwords.h>
55
#include <osisheadings.h>
56
#include <osisfootnotes.h>
57
#include <osisstrongs.h>
58
#include <osismorph.h>
59
#include <osislemma.h>
60
#include <osisredletterwords.h>
61
#include <osisscripref.h>
62
#include <thmlstrongs.h>
63
#include <thmlfootnotes.h>
64
#include <thmlheadings.h>
65
#include <thmlmorph.h>
66
#include <thmlvariants.h>
67
#include <thmllemma.h>
68
#include <thmlscripref.h>
69
#include <cipherfil.h>
74
#include <lzsscomprs.h>
75
#include <utf8greekaccents.h>
76
#include <utf8cantillation.h>
77
#include <utf8hebrewpoints.h>
78
#include <greeklexattribs.h>
79
#include <swfiltermgr.h>
81
#include "zipcomprs.h"
86
#include <utf8transliterator.h>
92
bool SWMgr::isICU = true;
94
bool SWMgr::isICU = false;
98
bool SWMgr::debug = false;
101
const char *SWMgr::globalConfPath = GLOBCONFPATH;
103
const char *SWMgr::globalConfPath = "/etc/sword.conf:/usr/local/etc/sword.conf";
107
SWFilter *tmpFilter = 0;
116
cipherFilters.clear();
117
optionFilters.clear();
118
cleanupFilters.clear();
120
tmpFilter = new ThMLVariants();
121
optionFilters.insert(FilterMap::value_type("ThMLVariants", tmpFilter));
122
cleanupFilters.push_back(tmpFilter);
124
tmpFilter = new GBFStrongs();
125
optionFilters.insert(FilterMap::value_type("GBFStrongs", tmpFilter));
126
cleanupFilters.push_back(tmpFilter);
128
tmpFilter = new GBFFootnotes();
129
optionFilters.insert(FilterMap::value_type("GBFFootnotes", tmpFilter));
130
cleanupFilters.push_back(tmpFilter);
132
tmpFilter = new GBFRedLetterWords();
133
optionFilters.insert(FilterMap::value_type("GBFRedLetterWords", tmpFilter));
134
cleanupFilters.push_back(tmpFilter);
136
tmpFilter = new GBFMorph();
137
optionFilters.insert(FilterMap::value_type("GBFMorph", tmpFilter));
138
cleanupFilters.push_back(tmpFilter);
140
tmpFilter = new GBFHeadings();
141
optionFilters.insert(FilterMap::value_type("GBFHeadings", tmpFilter));
142
cleanupFilters.push_back(tmpFilter);
144
tmpFilter = new OSISHeadings();
145
optionFilters.insert(FilterMap::value_type("OSISHeadings", tmpFilter));
146
cleanupFilters.push_back(tmpFilter);
148
tmpFilter = new OSISStrongs();
149
optionFilters.insert(FilterMap::value_type("OSISStrongs", tmpFilter));
150
cleanupFilters.push_back(tmpFilter);
152
tmpFilter = new OSISMorph();
153
optionFilters.insert(FilterMap::value_type("OSISMorph", tmpFilter));
154
cleanupFilters.push_back(tmpFilter);
156
tmpFilter = new OSISLemma();
157
optionFilters.insert(FilterMap::value_type("OSISLemma", tmpFilter));
158
cleanupFilters.push_back(tmpFilter);
160
tmpFilter = new OSISFootnotes();
161
optionFilters.insert(FilterMap::value_type("OSISFootnotes", tmpFilter));
162
cleanupFilters.push_back(tmpFilter);
164
tmpFilter = new OSISScripref();
165
optionFilters.insert(FilterMap::value_type("OSISScripref", tmpFilter));
166
cleanupFilters.push_back(tmpFilter);
168
tmpFilter = new OSISRedLetterWords();
169
optionFilters.insert(FilterMap::value_type("OSISRedLetterWords", tmpFilter));
170
cleanupFilters.push_back(tmpFilter);
172
tmpFilter = new ThMLStrongs();
173
optionFilters.insert(FilterMap::value_type("ThMLStrongs", tmpFilter));
174
cleanupFilters.push_back(tmpFilter);
176
tmpFilter = new ThMLFootnotes();
177
optionFilters.insert(FilterMap::value_type("ThMLFootnotes", tmpFilter));
178
cleanupFilters.push_back(tmpFilter);
180
tmpFilter = new ThMLMorph();
181
optionFilters.insert(FilterMap::value_type("ThMLMorph", tmpFilter));
182
cleanupFilters.push_back(tmpFilter);
184
tmpFilter = new ThMLHeadings();
185
optionFilters.insert(FilterMap::value_type("ThMLHeadings", tmpFilter));
186
cleanupFilters.push_back(tmpFilter);
188
tmpFilter = new ThMLLemma();
189
optionFilters.insert(FilterMap::value_type("ThMLLemma", tmpFilter));
190
cleanupFilters.push_back(tmpFilter);
192
tmpFilter = new ThMLScripref();
193
optionFilters.insert(FilterMap::value_type("ThMLScripref", tmpFilter));
194
cleanupFilters.push_back(tmpFilter);
196
tmpFilter = new UTF8GreekAccents();
197
optionFilters.insert(FilterMap::value_type("UTF8GreekAccents", tmpFilter));
198
cleanupFilters.push_back(tmpFilter);
200
tmpFilter = new UTF8HebrewPoints();
201
optionFilters.insert(FilterMap::value_type("UTF8HebrewPoints", tmpFilter));
202
cleanupFilters.push_back(tmpFilter);
204
tmpFilter = new UTF8Cantillation();
205
optionFilters.insert(FilterMap::value_type("UTF8Cantillation", tmpFilter));
206
cleanupFilters.push_back(tmpFilter);
208
tmpFilter = new GreekLexAttribs();
209
optionFilters.insert(FilterMap::value_type("GreekLexAttribs", tmpFilter));
210
cleanupFilters.push_back(tmpFilter);
212
// UTF8Transliterator needs to be handled differently because it should always available as an option, for all modules
214
transliterator = new UTF8Transliterator();
215
optionFilters.insert(FilterMap::value_type("UTF8Transliterator", transliterator));
216
options.push_back(transliterator->getOptionName());
217
cleanupFilters.push_back(transliterator);
220
gbfplain = new GBFPlain();
221
cleanupFilters.push_back(gbfplain);
223
thmlplain = new ThMLPlain();
224
cleanupFilters.push_back(thmlplain);
226
osisplain = new OSISPlain();
227
cleanupFilters.push_back(osisplain);
231
SWMgr::SWMgr(SWFilterMgr *filterMgr) {
232
commonInit(0, 0, true, filterMgr);
236
SWMgr::SWMgr(SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr) {
237
commonInit(iconfig, isysconfig, autoload, filterMgr);
241
void SWMgr::commonInit(SWConfig * iconfig, SWConfig * isysconfig, bool autoload, SWFilterMgr *filterMgr) {
242
this->filterMgr = filterMgr;
244
filterMgr->setParentMgr(this);
254
sysconfig = isysconfig;
264
SWMgr::SWMgr(const char *iConfigPath, bool autoload, SWFilterMgr *filterMgr) {
268
this->filterMgr = filterMgr;
270
filterMgr->setParentMgr(this);
275
int len = path.length();
276
if ((len < 1) || (iConfigPath[len-1] != '\\') && (iConfigPath[len-1] != '/'))
278
if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
279
stdstr(&prefixPath, path.c_str());
281
stdstr(&configPath, path.c_str());
284
if (FileMgr::existsDir(path.c_str(), "mods.d")) {
285
stdstr(&prefixPath, path.c_str());
287
stdstr(&configPath, path.c_str());
295
if (autoload && configPath)
304
for (FilterList::iterator it = cleanupFilters.begin(); it != cleanupFilters.end(); it++)
314
delete [] prefixPath;
317
delete [] configPath;
324
void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath, std::list<SWBuf> *augPaths) {
326
ConfigEntMap::iterator entry;
327
ConfigEntMap::iterator lastEntry;
329
char *envsworddir = getenv ("SWORD_PATH");
330
char *envhomedir = getenv ("HOME");
335
// check working directory
337
std::cerr << "Checking working directory for mods.conf...";
340
if (FileMgr::existsFile(".", "mods.conf")) {
344
std::cerr << "found\n";
347
stdstr(prefixPath, "./");
348
stdstr(configPath, "./mods.conf");
354
std::cerr << "\nChecking working directory for mods.d...";
357
if (FileMgr::existsDir(".", "mods.d")) {
361
std::cerr << "found\n";
364
stdstr(prefixPath, "./");
365
stdstr(configPath, "./mods.d");
371
// check environment variable SWORD_PATH
374
std::cerr << "\nChecking SWORD_PATH...";
377
if (envsworddir != NULL) {
381
std::cerr << "found (" << envsworddir << ")\n";
385
if ((envsworddir[strlen(envsworddir)-1] != '\\') && (envsworddir[strlen(envsworddir)-1] != '/'))
390
std::cerr << "\nChecking $SWORD_PATH for mods.conf...";
393
if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
397
std::cerr << "found\n";
400
stdstr(prefixPath, path.c_str());
402
stdstr(configPath, path.c_str());
408
std::cerr << "\nChecking $SWORD_PATH for mods.d...";
411
if (FileMgr::existsDir(path.c_str(), "mods.d")) {
415
std::cerr << "found\n";
418
stdstr(prefixPath, path.c_str());
420
stdstr(configPath, path.c_str());
427
// check for systemwide globalConfPath
431
std::cerr << "\nParsing " << globalConfPath << "...";
436
stdstr(&globPaths, globalConfPath);
437
for (gfp = strtok(globPaths, ":"); gfp; gfp = strtok(0, ":")) {
441
std::cerr << "\nChecking for " << gfp << "...";
444
if (FileMgr::existsFile(gfp))
451
SWBuf homeDir = getenv ("HOME");
452
if (homeDir.size() > 0) {
453
if ((homeDir[homeDir.size()-1] != '\\') && (homeDir[homeDir.size()-1] != '/'))
455
homeDir += ".sword/sword.conf";
456
if (FileMgr::existsFile(homeDir)) {
459
std::cerr << "\nOverriding any systemwide sword.conf with one found in users home directory." << gfp << "...";
461
sysConfPath = homeDir;
466
if (sysConfPath.size()) {
470
std::cerr << "found\n";
473
SWConfig etcconf(sysConfPath);
474
if ((entry = etcconf.Sections["Install"].find("DataPath")) != etcconf.Sections["Install"].end()) {
475
path = (*entry).second;
476
if (((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != '\\') && ((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != '/'))
481
std::cerr << "DataPath in " << sysConfPath << " is set to: " << path;
486
std::cerr << "\nChecking for mods.conf in DataPath ";
488
if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
492
std::cerr << "found\n";
495
stdstr(prefixPath, path.c_str());
497
stdstr(configPath, path.c_str());
503
std::cerr << "\nChecking for mods.d in DataPath ";
506
if (FileMgr::existsDir(path.c_str(), "mods.d")) {
510
std::cerr << "found\n";
513
stdstr(prefixPath, path.c_str());
515
stdstr(configPath, path.c_str());
521
entry = etcconf.Sections["Install"].lower_bound("AugmentPath");
522
lastEntry = etcconf.Sections["Install"].upper_bound("AugmentPath");
523
for (;entry != lastEntry; entry++) {
524
path = entry->second;
525
if ((entry->second.c_str()[strlen(entry->second.c_str())-1] != '\\') && (entry->second.c_str()[strlen(entry->second.c_str())-1] != '/'))
527
augPaths->push_back(path);
540
std::cerr << "\nChecking home directory for ~/.sword/mods.conf" << path;
543
if (envhomedir != NULL) {
545
if ((envhomedir[strlen(envhomedir)-1] != '\\') && (envhomedir[strlen(envhomedir)-1] != '/'))
548
if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
552
std::cerr << " found\n";
555
stdstr(prefixPath, path.c_str());
557
stdstr(configPath, path.c_str());
563
std::cerr << "\nChecking home directory for ~/.sword/mods.d" << path;
566
if (FileMgr::existsDir(path.c_str(), "mods.d")) {
570
std::cerr << "found\n";
573
stdstr(prefixPath, path.c_str());
575
stdstr(configPath, path.c_str());
583
void SWMgr::loadConfigDir(const char *ipath)
589
if ((dir = opendir(ipath))) {
591
while ((ent = readdir(dir))) {
592
if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
594
if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
596
newmodfile += ent->d_name;
598
SWConfig tmpConfig(newmodfile.c_str());
599
*config += tmpConfig;
601
else config = myconfig = new SWConfig(newmodfile.c_str());
605
if (!config) { // if no .conf file exist yet, create a default
607
if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
609
newmodfile += "globals.conf";
610
config = myconfig = new SWConfig(newmodfile.c_str());
616
void SWMgr::augmentModules(const char *ipath) {
618
if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
620
if (FileMgr::existsDir(path.c_str(), "mods.d")) {
621
char *savePrefixPath = 0;
622
char *saveConfigPath = 0;
623
SWConfig *saveConfig = 0;
624
stdstr(&savePrefixPath, prefixPath);
625
stdstr(&prefixPath, path.c_str());
627
stdstr(&saveConfigPath, configPath);
628
stdstr(&configPath, path.c_str());
630
config = myconfig = 0;
631
loadConfigDir(configPath);
635
stdstr(&prefixPath, savePrefixPath);
636
delete []savePrefixPath;
637
stdstr(&configPath, saveConfigPath);
638
delete []saveConfigPath;
639
(*saveConfig) += *config;
640
homeConfig = myconfig;
641
config = myconfig = saveConfig;
646
/***********************************************************************
647
* SWMgr::Load - loads actual modules
649
* RET: status - 0 = ok; -1 no config found; 1 = no modules installed
653
signed char SWMgr::Load() {
656
if (!config) { // If we weren't passed a config object at construction, find a config file
657
if (!configPath) // If we weren't passed a config path at construction...
658
findConfig(&configType, &prefixPath, &configPath, &augPaths);
661
loadConfigDir(configPath);
662
else config = myconfig = new SWConfig(configPath);
667
SectionMap::iterator Sectloop, Sectend;
668
ConfigEntMap::iterator Entryloop, Entryend;
672
for (Sectloop = config->Sections.lower_bound("Globals"), Sectend = config->Sections.upper_bound("Globals"); Sectloop != Sectend; Sectloop++) { // scan thru all 'Globals' sections
673
for (Entryloop = (*Sectloop).second.lower_bound("AutoInstall"), Entryend = (*Sectloop).second.upper_bound("AutoInstall"); Entryloop != Entryend; Entryloop++) // scan thru all AutoInstall entries
674
InstallScan((*Entryloop).second.c_str()); // Scan AutoInstall entry directory for new modules and install
676
if (configType) { // force reload on config object because we may have installed new modules
678
config = myconfig = 0;
679
loadConfigDir(configPath);
685
for (std::list<SWBuf>::iterator pathIt = augPaths.begin(); pathIt != augPaths.end(); pathIt++) {
686
augmentModules(pathIt->c_str());
688
// augment config with ~/.sword/mods.d if it exists ---------------------
689
char *envhomedir = getenv ("HOME");
690
if (envhomedir != NULL && configType != 2) { // 2 = user only
691
SWBuf path = envhomedir;
692
if ((envhomedir[strlen(envhomedir)-1] != '\\') && (envhomedir[strlen(envhomedir)-1] != '/'))
695
augmentModules(path.c_str());
697
// -------------------------------------------------------------------------
698
if ( !Modules.size() ) // config exists, but no modules
703
SWLog::systemlog->LogError("SWMgr: Can't find 'mods.conf' or 'mods.d'. Try setting:\n\tSWORD_PATH=<directory containing mods.conf>\n\tOr see the README file for a full description of setup options (%s)", (configPath) ? configPath : "<configPath is null>");
710
SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap §ion)
712
SWBuf description, datapath, misc1;
713
ConfigEntMap::iterator entry;
714
SWModule *newmod = 0;
715
SWBuf lang, sourceformat, encoding;
716
signed char direction, enc, markup;
718
description = ((entry = section.find("Description")) != section.end()) ? (*entry).second : (SWBuf)"";
719
lang = ((entry = section.find("Lang")) != section.end()) ? (*entry).second : (SWBuf)"en";
720
sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
721
encoding = ((entry = section.find("Encoding")) != section.end()) ? (*entry).second : (SWBuf)"";
722
datapath = prefixPath;
723
if ((prefixPath[strlen(prefixPath)-1] != '\\') && (prefixPath[strlen(prefixPath)-1] != '/'))
725
misc1 += ((entry = section.find("DataPath")) != section.end()) ? (*entry).second : (SWBuf)"";
726
char *buf = new char [ strlen(misc1.c_str()) + 1 ];
728
strcpy(buf, misc1.c_str());
729
// for (; ((*buf2) && ((*buf2 == '.') || (*buf2 == '/') || (*buf2 == '\\'))); buf2++);
730
for (; ((*buf2) && ((*buf2 == '/') || (*buf2 == '\\'))); buf2++);
731
if (!strncmp(buf2, "./", 2)) { //remove the leading ./ in the module data path to make it look better
738
section["AbsoluteDataPath"] = datapath;
740
if (!stricmp(sourceformat.c_str(), "GBF"))
742
else if (!stricmp(sourceformat.c_str(), "ThML"))
744
else if (!stricmp(sourceformat.c_str(), "OSIS"))
749
if (!stricmp(encoding.c_str(), "SCSU"))
751
else if (!stricmp(encoding.c_str(), "UTF-8")) {
754
else enc = ENC_LATIN1;
756
if ((entry = section.find("Direction")) == section.end()) {
757
direction = DIRECTION_LTR;
759
else if (!stricmp((*entry).second.c_str(), "rtol")) {
760
direction = DIRECTION_RTL;
762
else if (!stricmp((*entry).second.c_str(), "bidi")) {
763
direction = DIRECTION_BIDI;
766
direction = DIRECTION_LTR;
769
if ((!stricmp(driver, "zText")) || (!stricmp(driver, "zCom"))) {
770
SWCompress *compress = 0;
771
int blockType = CHAPTERBLOCKS;
772
misc1 = ((entry = section.find("BlockType")) != section.end()) ? (*entry).second : (SWBuf)"CHAPTER";
773
if (!stricmp(misc1.c_str(), "VERSE"))
774
blockType = VERSEBLOCKS;
775
else if (!stricmp(misc1.c_str(), "CHAPTER"))
776
blockType = CHAPTERBLOCKS;
777
else if (!stricmp(misc1.c_str(), "BOOK"))
778
blockType = BOOKBLOCKS;
780
misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS";
782
if (!stricmp(misc1.c_str(), "ZIP"))
783
compress = new ZipCompress();
786
if (!stricmp(misc1.c_str(), "LZSS"))
787
compress = new LZSSCompress();
790
if (!stricmp(driver, "zText"))
791
newmod = new zText(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str());
792
else newmod = new zCom(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str());
796
if (!stricmp(driver, "RawText")) {
797
newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
800
// backward support old drivers
801
if (!stricmp(driver, "RawGBF")) {
802
newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
805
if (!stricmp(driver, "RawCom")) {
806
newmod = new RawCom(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
809
if (!stricmp(driver, "RawFiles")) {
810
newmod = new RawFiles(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
813
if (!stricmp(driver, "HREFCom")) {
814
misc1 = ((entry = section.find("Prefix")) != section.end()) ? (*entry).second : (SWBuf)"";
815
newmod = new HREFCom(datapath.c_str(), misc1.c_str(), name, description.c_str());
818
int pos; //used for position of final / in AbsoluteDataPath, but also set to 1 for modules types that need to strip module name
819
if (!stricmp(driver, "RawLD")) {
820
newmod = new RawLD(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
824
if (!stricmp(driver, "RawLD4")) {
825
newmod = new RawLD4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
829
if (!stricmp(driver, "zLD")) {
830
SWCompress *compress = 0;
832
misc1 = ((entry = section.find("BlockCount")) != section.end()) ? (*entry).second : (SWBuf)"200";
833
blockCount = atoi(misc1.c_str());
834
blockCount = (blockCount) ? blockCount : 200;
836
misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS";
838
if (!stricmp(misc1.c_str(), "ZIP"))
839
compress = new ZipCompress();
842
if (!stricmp(misc1.c_str(), "LZSS"))
843
compress = new LZSSCompress();
846
newmod = new zLD(datapath.c_str(), name, description.c_str(), blockCount, compress, 0, enc, direction, markup, lang.c_str());
851
if (!stricmp(driver, "RawGenBook")) {
852
newmod = new RawGenBook(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
857
SWBuf &dp = section["AbsoluteDataPath"];
858
for (int i = dp.length() - 1; i; i--) {
866
// if a specific module type is set in the config, use this
867
if ((entry = section.find("Type")) != section.end())
868
newmod->Type(entry->second.c_str());
870
newmod->setConfig(§ion);
875
void SWMgr::AddGlobalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) {
876
for (;start != end; start++) {
877
FilterMap::iterator it;
878
it = optionFilters.find((*start).second);
879
if (it != optionFilters.end()) {
880
module->AddOptionFilter((*it).second); // add filter to module and option as a valid option
881
StringList::iterator loop;
882
for (loop = options.begin(); loop != options.end(); loop++) {
883
if (!strcmp((*loop).c_str(), (*it).second->getOptionName()))
886
if (loop == options.end()) // if we have not yet included the option
887
options.push_back((*it).second->getOptionName());
891
filterMgr->AddGlobalOptions(module, section, start, end);
893
module->AddOptionFilter(transliterator);
898
void SWMgr::AddLocalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
900
for (;start != end; start++) {
901
FilterMap::iterator it;
902
it = optionFilters.find((*start).second);
903
if (it != optionFilters.end()) {
904
module->AddOptionFilter((*it).second); // add filter to module
909
filterMgr->AddLocalOptions(module, section, start, end);
913
void SWMgr::AddRawFilters(SWModule *module, ConfigEntMap §ion) {
914
SWBuf sourceformat, cipherKey;
915
ConfigEntMap::iterator entry;
917
cipherKey = ((entry = section.find("CipherKey")) != section.end()) ? (*entry).second : (SWBuf)"";
918
if (cipherKey.length()) {
919
SWFilter *cipherFilter = new CipherFilter(cipherKey.c_str());
920
cipherFilters.insert(FilterMap::value_type(module->Name(), cipherFilter));
921
cleanupFilters.push_back(cipherFilter);
922
module->AddRawFilter(cipherFilter);
926
filterMgr->AddRawFilters(module, section);
930
void SWMgr::AddEncodingFilters(SWModule *module, ConfigEntMap §ion) {
932
filterMgr->AddEncodingFilters(module, section);
936
void SWMgr::AddRenderFilters(SWModule *module, ConfigEntMap §ion) {
938
ConfigEntMap::iterator entry;
940
sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
942
// Temporary: To support old module types
943
// TODO: Remove at 1.6.0 release?
944
if (!sourceformat.length()) {
945
sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
946
if (!stricmp(sourceformat.c_str(), "RawGBF"))
947
sourceformat = "GBF";
948
else sourceformat = "";
951
// process module - eg. follows
952
// if (!stricmp(sourceformat.c_str(), "GBF")) {
953
// module->AddRenderFilter(gbftortf);
957
filterMgr->AddRenderFilters(module, section);
962
void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap §ion)
965
ConfigEntMap::iterator entry;
967
sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
968
// Temporary: To support old module types
969
if (!sourceformat.length()) {
970
sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
971
if (!stricmp(sourceformat.c_str(), "RawGBF"))
972
sourceformat = "GBF";
973
else sourceformat = "";
976
if (!stricmp(sourceformat.c_str(), "GBF")) {
977
module->AddStripFilter(gbfplain);
979
else if (!stricmp(sourceformat.c_str(), "ThML")) {
980
module->AddStripFilter(thmlplain);
982
else if (!stricmp(sourceformat.c_str(), "OSIS")) {
983
module->AddStripFilter(osisplain);
987
filterMgr->AddStripFilters(module, section);
992
void SWMgr::CreateMods() {
993
SectionMap::iterator it;
994
ConfigEntMap::iterator start;
995
ConfigEntMap::iterator end;
996
ConfigEntMap::iterator entry;
999
for (it = config->Sections.begin(); it != config->Sections.end(); it++) {
1000
ConfigEntMap §ion = (*it).second;
1003
driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
1004
if (driver.length()) {
1005
newmod = CreateMod((*it).first, driver, section);
1007
start = (*it).second.lower_bound("GlobalOptionFilter");
1008
end = (*it).second.upper_bound("GlobalOptionFilter");
1009
AddGlobalOptions(newmod, section, start, end);
1011
start = (*it).second.lower_bound("LocalOptionFilter");
1012
end = (*it).second.upper_bound("LocalOptionFilter");
1013
AddLocalOptions(newmod, section, start, end);
1015
AddRawFilters(newmod, section);
1016
AddStripFilters(newmod, section);
1017
AddRenderFilters(newmod, section);
1018
AddEncodingFilters(newmod, section);
1020
Modules.insert(ModMap::value_type(newmod->Name(), newmod));
1027
void SWMgr::DeleteMods() {
1029
ModMap::iterator it;
1031
for (it = Modules.begin(); it != Modules.end(); it++)
1032
delete (*it).second;
1038
void SWMgr::InstallScan(const char *dirname)
1046
if (!access(dirname, 04)) {
1047
if ((dir = opendir(dirname))) {
1049
while ((ent = readdir(dir))) {
1050
if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
1051
newmodfile = dirname;
1052
if ((dirname[strlen(dirname)-1] != '\\') && (dirname[strlen(dirname)-1] != '/'))
1054
newmodfile += ent->d_name;
1058
targetName = configPath;
1059
if ((configPath[strlen(configPath)-1] != '\\') && (configPath[strlen(configPath)-1] != '/'))
1061
targetName += ent->d_name;
1062
conffd = open(targetName.c_str(), O_WRONLY|O_CREAT, S_IREAD|S_IWRITE);
1066
conffd = open(config->filename.c_str(), O_WRONLY|O_APPEND);
1068
lseek(conffd, 0L, SEEK_END);
1071
AddModToConfig(conffd, newmodfile.c_str());
1072
unlink(newmodfile.c_str());
1083
char SWMgr::AddModToConfig(int conffd, const char *fname)
1088
SWLog::systemlog->LogTimedInformation("Found new module [%s]. Installing...", fname);
1089
modfd = open(fname, O_RDONLY);
1091
write(conffd, &ch, 1);
1092
while (read(modfd, &ch, 1) == 1)
1093
write(conffd, &ch, 1);
1095
write(conffd, &ch, 1);
1101
void SWMgr::setGlobalOption(const char *option, const char *value)
1103
for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
1104
if ((*it).second->getOptionName()) {
1105
if (!stricmp(option, (*it).second->getOptionName()))
1106
(*it).second->setOptionValue(value);
1112
const char *SWMgr::getGlobalOption(const char *option)
1114
for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
1115
if ((*it).second->getOptionName()) {
1116
if (!stricmp(option, (*it).second->getOptionName()))
1117
return (*it).second->getOptionValue();
1124
const char *SWMgr::getGlobalOptionTip(const char *option)
1126
for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
1127
if ((*it).second->getOptionName()) {
1128
if (!stricmp(option, (*it).second->getOptionName()))
1129
return (*it).second->getOptionTip();
1136
StringList SWMgr::getGlobalOptions()
1142
StringList SWMgr::getGlobalOptionValues(const char *option)
1145
for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
1146
if ((*it).second->getOptionName()) {
1147
if (!stricmp(option, (*it).second->getOptionName())) {
1148
options = (*it).second->getOptionValues();
1149
break; // just find the first one. All option filters with the same option name should expect the same values
1157
signed char SWMgr::setCipherKey(const char *modName, const char *key) {
1158
FilterMap::iterator it;
1159
ModMap::iterator it2;
1161
// check for filter that already exists
1162
it = cipherFilters.find(modName);
1163
if (it != cipherFilters.end()) {
1164
((CipherFilter *)(*it).second)->getCipher()->setCipherKey(key);
1167
// check if module exists
1169
it2 = Modules.find(modName);
1170
if (it2 != Modules.end()) {
1171
SWFilter *cipherFilter = new CipherFilter(key);
1172
cipherFilters.insert(FilterMap::value_type(modName, cipherFilter));
1173
cleanupFilters.push_back(cipherFilter);
1174
(*it2).second->AddRawFilter(cipherFilter);