diff options
Diffstat (limited to 'src')
22 files changed, 93 insertions, 83 deletions
diff --git a/src/modules/comments/rawcom/rawcom.cpp b/src/modules/comments/rawcom/rawcom.cpp index f71b6ec..0f5396b 100644 --- a/src/modules/comments/rawcom/rawcom.cpp +++ b/src/modules/comments/rawcom/rawcom.cpp @@ -76,7 +76,9 @@ char *RawCom::getRawEntry() { *entrybuf = 0; readtext(key->Testament(), start, (size + 2), entrybuf); + entrybuf[size] = 0; + rawFilter(entrybuf, size, 0); // hack, decipher rawFilter(entrybuf, size, key); if (!isUnicode()) diff --git a/src/modules/common/rawverse.cpp b/src/modules/common/rawverse.cpp index f77fbe5..60b050b 100644 --- a/src/modules/common/rawverse.cpp +++ b/src/modules/common/rawverse.cpp @@ -199,7 +199,7 @@ void RawVerse::preptext(char *buf) */ void RawVerse::readtext(char testmt, long start, unsigned short size, char *buf) { - memset(buf, 0, size+1); + memset(buf, 0, size); if (!testmt) testmt = ((idxfp[1]) ? 1:2); if (size) { diff --git a/src/modules/common/zstr.cpp b/src/modules/common/zstr.cpp index cd1add5..972bc50 100644 --- a/src/modules/common/zstr.cpp +++ b/src/modules/common/zstr.cpp @@ -426,6 +426,9 @@ void zStr::getCompressedText(long block, long entry, char **buf) { flushCache(); unsigned long len = size; + + rawZFilter(*buf, len, 0); // 0 = decipher + compressor->zBuf(&len, *buf); char * rawBuf = compressor->Buf(0, &len); cacheBlock = new EntriesBlock(rawBuf, len); @@ -610,6 +613,10 @@ void zStr::flushCache() { compressor->Buf(rawBuf, &size); compressor->zBuf(&size); + char *buf = new char [ size * 2 ]; + memcpy(buf, compressor->zBuf(&size), size); // 1 = encipher + rawZFilter(buf, size, 1); // 1 = encipher + long zdxSize = lseek(zdxfd->getFd(), 0, SEEK_END); long zdtSize = lseek(zdtfd->getFd(), 0, SEEK_END); @@ -640,8 +647,7 @@ void zStr::flushCache() { lseek(zdxfd->getFd(), cacheBlockIndex * ZDXENTRYSIZE, SEEK_SET); lseek(zdtfd->getFd(), start, SEEK_SET); - rawBuf = compressor->zBuf(&size); - write(zdtfd->getFd(), rawBuf, size); + write(zdtfd->getFd(), buf, size); // add a new line to make data file easier to read in an editor write(zdtfd->getFd(), &nl, 2); diff --git a/src/modules/common/zverse.cpp b/src/modules/common/zverse.cpp index 600a317..e4c04cf 100644 --- a/src/modules/common/zverse.cpp +++ b/src/modules/common/zverse.cpp @@ -228,6 +228,9 @@ void zVerse::findoffset(char testmt, long idxoff, long *start, unsigned short *s printf ("Error reading compressed text\n"); return; } + + rawZFilter(pcCompText, ulCompSize, 0); // 0 = decipher + compressor->zBuf(&ulCompSize, pcCompText); if (cacheBuf) { @@ -326,28 +329,38 @@ void zVerse::flushCache() { unsigned long zsize, outzsize; idxoff = cacheBufIdx * 12; - size = outsize = zsize = outzsize = strlen(cacheBuf); - if (size) { -// if (compressor) { -// delete compressor; -// compressor = new LZSSCompress(); -// } - compressor->Buf(cacheBuf); - compressor->zBuf(&zsize); - outzsize = zsize; - - start = outstart = lseek(textfp[cacheTestament-1]->getFd(), 0, SEEK_END); - - outstart = archtosword32(start); - outsize = archtosword32(size); - outzsize = archtosword32(zsize); - - write(textfp[cacheTestament-1]->getFd(), compressor->zBuf(&zsize), zsize); - - lseek(idxfp[cacheTestament-1]->getFd(), idxoff, SEEK_SET); - write(idxfp[cacheTestament-1]->getFd(), &outstart, 4); - write(idxfp[cacheTestament-1]->getFd(), &outzsize, 4); - write(idxfp[cacheTestament-1]->getFd(), &outsize, 4); + if (cacheBuf) { + size = outsize = zsize = outzsize = strlen(cacheBuf); + if (size) { + // if (compressor) { + // delete compressor; + // compressor = new LZSSCompress(); + // } + compressor->Buf(cacheBuf); + compressor->zBuf(&zsize); + outzsize = zsize; + + char *buf = new char [ zsize * 2 ]; + memcpy(buf, compressor->zBuf(&zsize), zsize); + rawZFilter(buf, zsize, 1); // 1 = encipher + + start = outstart = lseek(textfp[cacheTestament-1]->getFd(), 0, SEEK_END); + + outstart = archtosword32(start); + outsize = archtosword32(size); + outzsize = archtosword32(zsize); + + write(textfp[cacheTestament-1]->getFd(), buf, zsize); + + delete [] buf; + + lseek(idxfp[cacheTestament-1]->getFd(), idxoff, SEEK_SET); + write(idxfp[cacheTestament-1]->getFd(), &outstart, 4); + write(idxfp[cacheTestament-1]->getFd(), &outzsize, 4); + write(idxfp[cacheTestament-1]->getFd(), &outsize, 4); + } + free(cacheBuf); + cacheBuf = 0; } dirtyCache = false; } diff --git a/src/modules/filters/cipherfil.cpp b/src/modules/filters/cipherfil.cpp index ad55396..ddb97b1 100644 --- a/src/modules/filters/cipherfil.cpp +++ b/src/modules/filters/cipherfil.cpp @@ -28,11 +28,17 @@ char CipherFilter::ProcessText(char *text, int maxlen, const SWKey *key, const S unsigned int len; // len = strlen(text); len = maxlen; - if (len > 0) { - cipher->cipherBuf(&len, text); - strncpy(text, cipher->Buf(), (len < (unsigned int)maxlen) ? len : maxlen); - } - text[maxlen] = 0; - text[maxlen+1] = 0; + if (len > 0) { + if (!key) { // hack, using key to determine encipher, or decipher + cipher->cipherBuf(&len, text); + memcpy(text, cipher->Buf(), (len < (unsigned int)(maxlen)) ? len : maxlen); + } + else if ((unsigned long)key == 1) { + cipher->Buf(text, len); + cipher->cipherBuf(&len); + memcpy(text, cipher->cipherBuf(&len), (len < (unsigned int)(maxlen)) ? len : maxlen); + } + } +// text[maxlen] = 0; return 0; } diff --git a/src/modules/filters/latin1utf16.cpp b/src/modules/filters/latin1utf16.cpp index 75ee998..7bbcafb 100644 --- a/src/modules/filters/latin1utf16.cpp +++ b/src/modules/filters/latin1utf16.cpp @@ -18,7 +18,9 @@ char Latin1UTF16::ProcessText(char *text, int maxlen, const SWKey *key, const SW unsigned char *from; unsigned short *to; int len; - + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; + len = strlen(text) + 1; // shift string to right of buffer if (len < maxlen) { memmove(&text[maxlen - len], text, len); diff --git a/src/modules/filters/latin1utf8.cpp b/src/modules/filters/latin1utf8.cpp index 91af8dc..2a76306 100644 --- a/src/modules/filters/latin1utf8.cpp +++ b/src/modules/filters/latin1utf8.cpp @@ -18,7 +18,8 @@ char Latin1UTF8::ProcessText(char *text, int maxlen, const SWKey *key, const SWM { unsigned char *to, *from; int len; - + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; len = strlen(text) + 1; if (len == maxlen + 1) maxlen = (maxlen + 1) * FILTERPAD; diff --git a/src/modules/filters/scsuutf8.cpp b/src/modules/filters/scsuutf8.cpp index d0d5ceb..15fd015 100644 --- a/src/modules/filters/scsuutf8.cpp +++ b/src/modules/filters/scsuutf8.cpp @@ -64,6 +64,8 @@ char SCSUUTF8::ProcessText(char *text, int len, const SWKey *key, const SWModule unsigned char *to, *from; unsigned long buflen = len * FILTERPAD; char active = 0, mode = 0; + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; static unsigned short start[8] = {0x0000,0x0080,0x0100,0x0300,0x2000,0x2080,0x2100,0x3000}; static unsigned short slide[8] = {0x0080,0x00C0,0x0400,0x0600,0x0900,0x3040,0x30A0,0xFF00}; diff --git a/src/modules/filters/utf16utf8.cpp b/src/modules/filters/utf16utf8.cpp index 5a7719f..aa4215b 100644 --- a/src/modules/filters/utf16utf8.cpp +++ b/src/modules/filters/utf16utf8.cpp @@ -21,6 +21,8 @@ char UTF16UTF8::ProcessText(char *text, int maxlen, const SWKey *key, const SWMo int len; unsigned long uchar; unsigned short schar; + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; len = 0; from = (unsigned short*) text; diff --git a/src/modules/filters/utf8arshaping.cpp b/src/modules/filters/utf8arshaping.cpp index 5121f48..4427e62 100644 --- a/src/modules/filters/utf8arshaping.cpp +++ b/src/modules/filters/utf8arshaping.cpp @@ -28,6 +28,8 @@ UTF8arShaping::~UTF8arShaping() { char UTF8arShaping::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module) { UChar *ustr, *ustr2; + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; int32_t len = strlen(text); ustr = new UChar[len]; diff --git a/src/modules/filters/utf8bidireorder.cpp b/src/modules/filters/utf8bidireorder.cpp index 8fa7280..bdaae52 100644 --- a/src/modules/filters/utf8bidireorder.cpp +++ b/src/modules/filters/utf8bidireorder.cpp @@ -28,6 +28,8 @@ UTF8BiDiReorder::~UTF8BiDiReorder() { char UTF8BiDiReorder::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module) { UChar *ustr, *ustr2; + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; int32_t len = strlen(text); ustr = new UChar[len]; //each char could become a surrogate pair diff --git a/src/modules/filters/utf8html.cpp b/src/modules/filters/utf8html.cpp index 7487815..f337698 100644 --- a/src/modules/filters/utf8html.cpp +++ b/src/modules/filters/utf8html.cpp @@ -19,6 +19,8 @@ char UTF8HTML::ProcessText(char *text, int maxlen, const SWKey *key, const SWMod int len; char digit[10]; unsigned long ch; + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; len = strlenw(text) + 2; // shift string to right of buffer if (len < maxlen) { diff --git a/src/modules/filters/utf8latin1.cpp b/src/modules/filters/utf8latin1.cpp index 6cc1acd..07299fe 100644 --- a/src/modules/filters/utf8latin1.cpp +++ b/src/modules/filters/utf8latin1.cpp @@ -22,6 +22,8 @@ char UTF8Latin1::ProcessText(char *text, int maxlen, const SWKey *key, const SWM unsigned long uchar; unsigned char significantFirstBits, subsequent; + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; len = strlen(text) + 1; // shift string to right of buffer if (len < maxlen) { memmove(&text[maxlen - len], text, len); diff --git a/src/modules/filters/utf8nfc.cpp b/src/modules/filters/utf8nfc.cpp index df9e090..861a291 100644 --- a/src/modules/filters/utf8nfc.cpp +++ b/src/modules/filters/utf8nfc.cpp @@ -25,6 +25,8 @@ UTF8NFC::~UTF8NFC() { char UTF8NFC::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module) { + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; int32_t len = strlen(text) * 2; source = new UChar[len + 1]; //each char could become a surrogate pair diff --git a/src/modules/filters/utf8nfkd.cpp b/src/modules/filters/utf8nfkd.cpp index 450cbbf..d790266 100644 --- a/src/modules/filters/utf8nfkd.cpp +++ b/src/modules/filters/utf8nfkd.cpp @@ -25,6 +25,8 @@ UTF8NFKD::~UTF8NFKD() { char UTF8NFKD::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module) { + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; int32_t len = strlen(text) * 2; source = new UChar[len + 1]; //each char could become a surrogate pair diff --git a/src/modules/filters/utf8utf16.cpp b/src/modules/filters/utf8utf16.cpp index 9aea6fe..33248a9 100644 --- a/src/modules/filters/utf8utf16.cpp +++ b/src/modules/filters/utf8utf16.cpp @@ -23,6 +23,8 @@ char UTF8UTF16::ProcessText(char *text, int maxlen, const SWKey *key, const SWMo unsigned char significantFirstBits, subsequent; unsigned short schar; + if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering + return -1; len = strlen(text) + 1; // shift string to right of buffer if (len < maxlen) { memmove(&text[maxlen - len], text, len); diff --git a/src/modules/genbook/rawgenbook/rawgenbook.cpp b/src/modules/genbook/rawgenbook/rawgenbook.cpp index e22532a..89367b5 100644 --- a/src/modules/genbook/rawgenbook/rawgenbook.cpp +++ b/src/modules/genbook/rawgenbook/rawgenbook.cpp @@ -112,7 +112,9 @@ char *RawGenBook::getRawEntry() { *entryBuf = 0; lseek(bdtfd->getFd(), offset, SEEK_SET); read(bdtfd->getFd(), entryBuf, size); + entryBuf[size] = 0; + rawFilter(entryBuf, size, 0); // hack, decipher rawFilter(entryBuf, size, key); if (!isUnicode()) diff --git a/src/modules/lexdict/rawld/rawld.cpp b/src/modules/lexdict/rawld/rawld.cpp index 058679a..2e5c90a 100644 --- a/src/modules/lexdict/rawld/rawld.cpp +++ b/src/modules/lexdict/rawld/rawld.cpp @@ -90,6 +90,8 @@ char RawLD::getEntry(long away) if (!(retval = findoffset(buf, &start, &size, away))) { readtext(start, &size, &idxbuf, &entrybuf); + rawFilter(entrybuf, size, 0); // hack, decipher + rawFilter(entrybuf, size, key); entrySize = size; // support getEntrySize call if (!key->Persist()) // If we have our own key *key = idxbuf; // reset it to entry index buffer diff --git a/src/modules/lexdict/rawld4/rawld4.cpp b/src/modules/lexdict/rawld4/rawld4.cpp index 1bdf22f..435767d 100644 --- a/src/modules/lexdict/rawld4/rawld4.cpp +++ b/src/modules/lexdict/rawld4/rawld4.cpp @@ -91,6 +91,8 @@ char RawLD4::getEntry(long away) *entrybuf = 0; if (!(retval = findoffset(buf, &start, &size, away))) { readtext(start, &size, &idxbuf, &entrybuf); + rawFilter(entrybuf, size, 0); // hack, decipher + rawFilter(entrybuf, size, key); entrySize = size; // support getEntrySize call if (!key->Persist()) // If we have our own key *key = idxbuf; // reset it to entry index buffer diff --git a/src/modules/lexdict/zld/zld.cpp b/src/modules/lexdict/zld/zld.cpp index 047effa..f444f61 100644 --- a/src/modules/lexdict/zld/zld.cpp +++ b/src/modules/lexdict/zld/zld.cpp @@ -93,6 +93,8 @@ char zLD::getEntry(long away) { entrybuf = new char [ size * FILTERPAD ]; strcpy(entrybuf, ebuf); + rawFilter(entrybuf, size, key); + entrySize = size; // support getEntrySize call if (!key->Persist()) // If we have our own key *key = idxbuf; // reset it to entry index buffer diff --git a/src/modules/texts/rawtext/rawtext.cpp b/src/modules/texts/rawtext/rawtext.cpp index cfaaa37..489ea1c 100644 --- a/src/modules/texts/rawtext/rawtext.cpp +++ b/src/modules/texts/rawtext/rawtext.cpp @@ -105,10 +105,12 @@ char *RawText::getRawEntry() { *entrybuf = 0; readtext(key->Testament(), start, (size + 2), entrybuf); + entrybuf[size] = 0; + rawFilter(entrybuf, size, 0); // hack, decipher rawFilter(entrybuf, size, key); - if (!isUnicode()) + if (!isUnicode()) preptext(entrybuf); if (this->key != key) // free our key if we created a VerseKey diff --git a/src/modules/texts/ztext/ztext.cpp b/src/modules/texts/ztext/ztext.cpp index c774693..77a45b1 100644 --- a/src/modules/texts/ztext/ztext.cpp +++ b/src/modules/texts/ztext/ztext.cpp @@ -60,50 +60,10 @@ zText::~zText() char *zText::getRawEntry() { -/* - long start; - unsigned long size; - unsigned long destsize; - char *tmpbuf; - char *dest; - VerseKey *lkey = (VerseKey *) SWModule::key; - char sizebuf[3]; - - lkey->Verse(0); - if (chapcache != lkey->Index()) { - findoffset(lkey->Testament(), lkey->Index(), &start, &((unsigned short) size)); - readtext(lkey->Testament(), start, 3, sizebuf); - memcpy(&size, sizebuf, 2); - tmpbuf = new char [ size + 1 ]; - readtext(lkey->Testament(), start + 2, size + 1 , tmpbuf); - //zBuf(&size, tmpbuf); - dest = new char [ (size*4) + 1 ]; - uncompress((Bytef *)dest, &destsize, (Bytef *) tmpbuf, size); - chapcache = lkey->Index(); - delete [] tmpbuf; - } - - //findoffset(key->Testament(), key->Index(), &start, &size); - findoffset(lkey->Testament(), lkey->Index(), &start, &((unsigned short) size)); - - if (versebuf) - delete [] versebuf; - versebuf = new char [ size + 1 ]; - //memcpy(versebuf, Buf(), size); - memcpy(versebuf, dest, destsize); - delete [] dest; - - preptext(versebuf); - - return versebuf; -*/ - long start = 0; unsigned short size = 0; VerseKey *key = 0; - //printf ("zText char *\n"); - // see if we have a VerseKey * or decendant try { key = SWDYNAMIC_CAST(VerseKey, this->key); @@ -113,12 +73,9 @@ char *zText::getRawEntry() if (!key) key = new VerseKey(this->key); - //printf ("checking cache\n"); - //printf ("finding offset\n"); findoffset(key->Testament(), key->Index(), &start, &size); entrySize = size; // support getEntrySize call - //printf ("deleting previous buffer\n"); unsigned long newsize = (size + 2) * FILTERPAD; if (newsize > entrybufallocsize) { if (entrybuf) @@ -128,22 +85,17 @@ char *zText::getRawEntry() } *entrybuf = 0; - //printf ("getting text\n"); zreadtext(key->Testament(), start, (size + 2), entrybuf); - //printf ("got text\n"); rawFilter(entrybuf, size, key); - //printf ("preparing text\n"); - if (!isUnicode()) + if (!isUnicode()) preptext(entrybuf); if (this->key != key) // free our key if we created a VerseKey delete key; - //printf ("returning text\n"); return entrybuf; - } |