/* Copyright 2017-2025 m-privacy GmbH.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

#ifndef __SAUTOTRANSFER_MIME_H__
#define __SAUTOTRANSFER_MIME_H__

#if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__)

#include <list>
#include <magic.h>
#include <pwd.h>

#include <rfb/SAutotransferDirWatcher.h>
class SAutotransferMime: public SAutotransferDirWatcher
{
public:
	SAutotransferMime();
	std::string getDirToWatch() const override;
	void processFile(char* filename) override;

	// Move this FROM private TO public:
	bool checkFile(char* filename);
	int checkMagic(char* filename);

private:
	// Keep other methods private
	bool checkSingleFile(char *filename, char **mimeTypeLibmagicP, char **reasonP);
	bool checkTree(char *dirname);
	bool unpackAndCheck(char *name);
	void checkGlibPacker(char *filename, const char *mimeTypeLibmagic);
	void loadAllowedMimeTypes();
	void initMagicFile();
	void logTransferIfNecessary(const char* filename, const char* mimeType, const char* reason, const bool magicOk);

	// Private member variables
	magic_t magicSet;
	std::list<const char*> allowedMimeTypes;
	std::list<const char*> packerCheckTypes;
	time_t lastAllowedMimeTypesRead;
	char* autotransferNowDir;
};
#endif /* #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) */
#endif /* __SAUTOTRANSFER_MIME_H__ */
