00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ 00002 00003 /* AbiSource 00004 * 00005 * Copyright (C) 2009 Marc 'Foddex' Oude Kotte <foddex@foddex.net> 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation; either version 2 00010 * of the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00020 * 02111-1307, USA. 00021 */ 00022 00023 #include <libxml/parser.h> 00024 #include <libxml/xmlwriter.h> 00025 #include <string> 00026 #include <vector> 00027 #include <gsf/gsf-utils.h> 00028 #include "ut_rand.h" 00029 #include "ut_jpeg.h" 00030 #include "ut_go_file.h" 00031 #include "ut_bytebuf.h" 00032 #include "png.h" 00033 #include "xap_Module.h" 00034 #include "xap_App.h" 00035 #include "xav_View.h" 00036 #include "ev_EditMethod.h" 00037 #include "ap_Args.h" 00038 #include <gsf/gsf-input.h> 00039 00040 using namespace std; 00041 00042 class abiword_garble; 00043 00044 class abiword_document { 00045 00046 private: 00047 string mFilename; 00048 xmlDocPtr mDocument; 00049 abiword_garble* mAbiGarble; 00050 size_t mCharsGarbled; 00051 size_t mImagesGarbled; 00052 string mReplaceString; // just a string whose allocated memory is re-used for performance :-) 00053 00054 void garble_node( xmlNodePtr node ); 00055 void garble_image_node( xmlNodePtr node ); 00056 bool garble_png( void*& data, size_t& size ); 00057 bool garble_jpeg( void*& data, size_t& size ); 00058 void garble_image_line( char* line, size_t bytes ); 00059 char get_random_char(); 00060 public: 00061 abiword_document( abiword_garble* abigarble, const string& filename ); 00062 ~abiword_document(); 00063 void garble(); 00064 void save(); 00065 }; 00066 00067 class abiword_garble { 00068 00069 private: 00070 vector<string> mFilenames; 00071 bool mVerbose; 00072 bool mInitialized; 00073 bool mImageGarbling; 00074 00075 void usage(); 00076 public: 00077 abiword_garble( int argc, const char** argv ); 00078 int run(); 00079 bool verbose() const { return mVerbose; } 00080 bool initialized() const { return mInitialized; } 00081 bool image_garbling() const { return mImageGarbling; } 00082 };
1.5.5