void LZ78::decompress(const std::string* outfile) { unsigned long last_index = 0x00000000; decode_dict = new std::map<unsigned long, std::vector<unsigned char> > (); //fprintf(stderr, "Max map size is %lu\n", this->decode_dict->max_size()); unsigned long maskIndex, eofile; eofile = EOFILE; unsigned char newEntry; debug("Decompressing...", INFO); if (this->filename != NULL) { debug("Opening from file : " + *(this->filename), DEBUG); if (!freopen(this->filename->c_str(), "rb", stdin)) { debug("Error opening file !", CRITICAL); } } if (outfile != NULL) { debug("Opening outfile : " + *outfile, DEBUG); if (!freopen(outfile->c_str(), "wb", stdout)) { debug("Error opening file for output !", CRITICAL); } } bool terminated = false; int byteIndex; unsigned char currByte, lookahead1, lookahead2; long lastPos; std::vector<unsigned char> part; do { maskIndex = 0; for (byteIndex = 0; byteIndex < DICT_NUMBYTE - 1; byteIndex++) { currByte = fgetc(stdin); maskIndex = maskIndex + currByte; maskIndex = maskIndex << 8; } currByte = fgetc(stdin); maskIndex = maskIndex + currByte; //fprintf(stderr, "Maskindex = %lu\n ******************************\n", maskIndex); //cerr << "\t Index is:" << std::bitset < 24 > (maskIndex) << std::endl; if (IS_MATCH(maskIndex)) { debug("MATCH !", DEBUG); } else { debug("MISS !", DEBUG); } if (maskIndex == eofile) { debug("end of file", DEBUG); terminated = true; } else { //fprintf(stderr,"index : %lu\n",CLEAN_FLAG(maskIndex)); newEntry = fgetc(stdin); //fprintf(stderr,"Entry = %x\n",newEntry); lastPos = ftell(stdin); bool eofMark = false; if (DICT_NUMBYTE>1) { lookahead1 = fgetc(stdin); if (newEntry == 0x7F && lookahead1 == 0xFF) eofMark = true; } if (DICT_NUMBYTE>2) { lookahead2 = fgetc(stdin); if (eofMark && lookahead2 == 0xFF) eofMark = true; else eofMark = false; } if (!eofMark) { fseek(stdin, 1-DICT_NUMBYTE, SEEK_CUR); //fprintf(stderr, "last index is %lu \n", last_index); last_index += 0x00000001; if (IS_MATCH(maskIndex)) { debug("Decoding a match in dict", DDEBUG); // match -> 1??????? ........ where ?? is dict index, ... is symbol coding unsigned long index = CLEAN_FLAG(maskIndex); //cerr << "\t Real Index is:" << std::bitset < 24 > (index) << std::endl; part.clear(); part = getEntry(index); if (part.size() ==0) { //fprintf(stderr,"\nsize0!\n"); debug("Entry not found in dictionary, internal error !",CRITICAL); return; // break; } debug("Entry has been found", DEBUG); part.push_back(newEntry); //fprintf(stderr,"Pushing new entry in dictionary : %x\n",newEntry); debug("String appended", DDEBUG); this->decode_dict->insert(std::pair<unsigned long, std::vector<unsigned char> > (last_index, std::vector<unsigned char>(part))); if (this->decode_dict->size() >=MAX_DICSIZE) { this->decode_dict->clear(); last_index = 0x00000000; } for (std::vector<unsigned char>::iterator it = part.begin(); it!=part.end(); ++it) { fputc(*it, stdout); } part.clear(); } else { debug("No match for current DWORD Adding to dictionary", DDEBUG); std::vector<unsigned char> vect; vect.push_back(newEntry); this->decode_dict->insert(std::pair<unsigned long, std::vector<unsigned char> > (last_index, vect)); if (this->decode_dict->size() >=MAX_DICSIZE) { this->decode_dict->clear(); last_index = 0x00000000; } fputc(newEntry, stdout); } } else { debug("Special EOF situation !", DEBUG); //fprintf(stderr,"lookahead1 = %x \tlookahead2 = %x \t newEntry = %x\n",lookahead1,lookahead2,newEntry); if (IS_MATCH(maskIndex)) { debug("Decoding a match in dict", DDEBUG); unsigned long index = CLEAN_FLAG(maskIndex); part.clear(); part = getEntry(index); if (part.size() ==0) { //fprintf(stderr,"\nsize0!\n"); //fprintf(stderr,"Cannot find entry %lu\n",index); debug("Entry not found in dictionary, internal error !",CRITICAL); return; } else { debug("Entry has been found", DEBUG); //fprintf(stderr,"Found entry %lu\n",index); for (std::vector<unsigned char>::iterator it = part.begin(); it!=part.end(); ++it) { //fprintf(stderr,"->0x%x",*it); fputc(*it, stdout); } } } part.clear(); terminated = true; } } } while (maskIndex != eofile && !terminated); if (part.size()!=0) { debug("hm, Part is not empty !",CRITICAL); } debug("Closing stdin FILE descriptor", DDEBUG); fclose(stdin); debug("Closing stdout FILE descriptor", DDEBUG); fclose(stdout); debug("Done !", INFO); }
bool Kleo::KConfigBasedKeyFilter::matches( const GpgME::Key & key ) const { #ifdef MATCH #undef MATCH #endif #define MATCH(member,method) \ if ( member != DoesNotMatter && key.method() != bool( member == Set ) ) \ return false #define IS_MATCH(what) MATCH( m##what, is##what ) #define CAN_MATCH(what) MATCH( mCan##what, can##what ) IS_MATCH( Revoked ); IS_MATCH( Expired ); IS_MATCH( Disabled ); IS_MATCH( Root ); CAN_MATCH( Encrypt ); CAN_MATCH( Sign ); CAN_MATCH( Certify ); CAN_MATCH( Authenticate ); MATCH( mHasSecret, isSecret ); #undef MATCH if ( mIsOpenPGP != DoesNotMatter && bool( key.protocol() == GpgME::Context::OpenPGP ) != bool( mIsOpenPGP == Set ) ) return false; if ( mWasValidated != DoesNotMatter && bool( key.keyListMode() & GpgME::Context::Validate ) != bool( mWasValidated == Set ) ) return false; switch ( mOwnerTrust ) { default: case LevelDoesNotMatter: break; case Is: if ( key.ownerTrust() != mOwnerTrustReferenceLevel ) return false; break; case IsNot: if ( key.ownerTrust() == mOwnerTrustReferenceLevel ) return false; break; case IsAtLeast: if ( (int)key.ownerTrust() < (int)mOwnerTrustReferenceLevel ) return false; break; case IsAtMost: if ( (int)key.ownerTrust() > (int)mOwnerTrustReferenceLevel ) return false; break; } const GpgME::UserID uid = key.userID(0); switch ( mValidity ) { default: case LevelDoesNotMatter: break; case Is: if ( uid.validity() != mValidityReferenceLevel ) return false; break; case IsNot: if ( uid.validity() == mValidityReferenceLevel ) return false; break; case IsAtLeast: if ( (int)uid.validity() < (int)mValidityReferenceLevel ) return false; break; case IsAtMost: if ( (int)uid.validity() > (int)mValidityReferenceLevel ) return false; break; } return true; }