1. Andreas Tscharner
  2. lrc


lrc / src / ResourceData.hxx

//      ResourceData.hxx
//      Copyright 2011, 2012 Andreas Tscharner <andy@vis.ethz.ch>
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU Lesser General Public License as
//      published by the Free Software Foundation; either version 3 of the
//      License, or (at your option) any later version.
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      GNU General Public License for more details.
//      You should have received a copy of the GNU Lesser General Public
//      License along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.

/*! \file ResourceData.hxx
 * This file contains the class definition of the ResourceData class.
 * ResourceData is derived from Resource, but contains a lot more
 * information
 * \author Andreas Tscharner
 * \date 2012-01-07


// Included files
#include <tuple>
#include "include/Resource.hxx"
#include "include/CompressDecompress.hxx"
#include "include/EncryptDecrypt.hxx"

//! Define a datatype of its own for the file position in the input file
typedef std::tuple<int, int> inFilePosition;

/*! \class ResourceData
 *  \brief Internal class for resource with more information
 * This class contains all needed data of a resource. It is derived from
 * Resource
class ResourceData : public lrc::Resource
		unsigned char *m_password;          //!< Password for encryption

		char *m_filename;                   //!< Filename of file containing resource
		lrc::EncryptionType m_encryption;   //!< Type of encryption for this resource
		lrc::CompressionType m_compression; //!< Type of compression for this resource
		inFilePosition m_inFilePosition;    //!< Position of resource in RC file

		char *m_errorMsg;                   //!< Error message (if any)
		/*! \brief Set new error message
		 * This method clears an old error message (if any) and sets the new
		 * given one
		 * \param[in] p_newErrMsg New error message
		void set_error_msg(char *);

		/*! \brief Constructor
		 * Standard constructor to initialize the class
		/*! \brief Destructor
		 * Cleans up memory used from the class

		/*! \brief Set resource identifier
		 * Method to set the internal resource identifier
		 * \param[in] p_resIdent Resource identifier
		void set_ident(const char *);

		/*! \brief Set file containing resource
		 * Method to set the filename containing the resource data
		 * \param[in] p_resFilename Filename containing resource
		void set_file(const char *);
		/*! \brief Return filename
		 * This method returns the filename of the resource data file of
		 * this very resource
		 * \return Filename of resource data file
		char *get_file(void);

		/*! \brief Set encryption type
		 * Method to set encryption type of resource
		 * \param[in] p_resEncryption Encryption type
		 * \param[in] p_password Password for encryption
		void set_encryption(lrc::EncryptionType, const unsigned char *);
		/*! \brief Return encryption type
		 * Method to return the encryption type of this very resource
		 * \return Encryption type of resource
		lrc::EncryptionType get_encryption(void);

		/*! \brief Set compression type
		 * Method to set compression type of resource
		 * \param[in] p_resCompression Compression type
		void set_compression(lrc::CompressionType);
		/*! \brief Return compression type
		 * Method to return the compression type of this very resource
		 * \return Compression type of resource
		lrc::CompressionType get_compression(void);

		/*! \brief Set position of resource description
		 * Method to set the position of the resource description in the RC
		 * file. It is used for a sane error message in the collecting
		 * process
		 * \param[in] p_line Line number in RC file
		 * \param[in] p_col Column number in RC file
		 * \see Collector
		void set_rc_position(int, int);
		/*! \brief Return resource description position
		 * Method to return the resource description in the RC file of this
		 * very resource
		 * \return Resource position in RC file
		inFilePosition get_rc_position(void);

		/*! \brief Prepare resource for collecting
		 * This method loads the file containing the resource, compresses
		 * and encrypts the data and provides it for the collectors
		 * \param[out] p_resData Resource data for collector
		 * \param[out] p_resSize Size of resource data
		 * \retval NO_ERROR Resource successfully prepared
		 * \retval ERROR_INVALID_PARAMETER The provided parameter was
		 *                                 nullptr
		 * \retval ERROR_FILE_NOT_FOUND The resource file could not be found
		 * \retval ERROR_COMPRESSION_NOT_AVAILABLE The selected compression
		 *                                         is not available
		 * \retval ERROR_ENCRYPTION_NOT_AVAILABLE The selected encryption is
		 *                                        not availale
		 * \retval ERROR_FILE_OPEN The file could not be opened
		 * \retval ERROR_FILE_READ An error occurred while reading the file
		 * \remarks The caller is responsible to free the used memory
		int prepare_resource_from_file(unsigned char **, size_t &);
		/*! \brief Get resource data from compressed and encrypted chunk of
		 *         memory
		 * This method extracts the information of the class from a
		 * compressed and encrypted chunk of memory. It is usually used
		 * after the data is loaded from file
		 * \param[in] p_dataStart Start adress of memory block
		 * \param[in] p_resEntry Entry block of resource
		 * \param[in] p_password Password if resource is encrypted
		 * \retval NO_ERROR Resource data successfully extracted
		 * \retval ERROR_INVALID_PARAMETER One or more provided parameters
		 * \retval ERROR_COMPRESSION_NOT_AVAILABLE The required compression
		 *                                         class is not available
		 * \retval ERROR_ENCRYPTION_NOT_AVAILABLE The required encryption
		 *                                        class is not available
		 * \retval ERROR_ENCRYPTION_DECRYPT An error occurred while
		 *                                  decrypting the data
		 * \retval ERROR_COMPRESSION_DECOMPRESS An error occurred while
		 *                                      decompressing the data
		 * \remarks The caller is responsible to free the returned class
		int get_data_from_memory(unsigned char *, resEntry, const unsigned char *p_password = nullptr);

		/*! \brief Return error message
		 * This method returns the internal error message (if there is any)
		 * and clears it
		 * \return Internal error message
		 * \remarks The caller is responsible to free the used memory for
		 *          the message
		char *get_error_msg(void);

#endif /* __RESOURCEDATA_HXX__ */