From 8c20dc919f7d54eb48fb60f39ba5e1d466a70763 Mon Sep 17 00:00:00 2001 From: Mavridis Philippe Date: Wed, 13 Jan 2021 19:26:24 +0200 Subject: Initial commit Signed-off-by: Mavridis Philippe --- src/ctcron.h | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 src/ctcron.h (limited to 'src/ctcron.h') diff --git a/src/ctcron.h b/src/ctcron.h new file mode 100644 index 0000000..b8d03fe --- /dev/null +++ b/src/ctcron.h @@ -0,0 +1,154 @@ +/*************************************************************************** + * CT Cron Header * + * -------------------------------------------------------------------- * + * Copyright (C) 1999, Gary Meyer * + * -------------------------------------------------------------------- * + * This program 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. * + ***************************************************************************/ + +#ifndef CTCRON_H +#define CTCRON_H + +// Do not introduce any Qt or KDE dependencies into the "CT"-prefixed classes. +// I want to be able to reuse these classes with another GUI toolkit. -GM 11/99 + +#include +#include +#include + +#include // Anarchy! -WABA + +class CTException; +class CTTask; +class CTVariable; + +struct passwd; + +/** + * A user (encapsulation of a single crontab file). Encapsulates + * file i/o, parsing, tokenization, and natural language description. + */ +class CTCron +{ +public: + +/** + * Constructs the scheduled tasks, environment variables from crontab + * files and obtains some information about the user from the system. + * + * Default is to construct from the user's crontab. Can also be called, + * passing TRUE, to construct from the system crontab. Throws an + * exception if the crontab file can not be found, read, or parsed. + */ + CTCron(bool _syscron = false, std::string _login = ""); +/** + * If you already have a struct passwd, use it instead. This + * is never used for the system crontab. + */ + CTCron(const struct passwd * _login = 0L); + +/** + * Copy one user's tasks and environement variables to another user. + */ + void operator = (const CTCron& source); + +/** + * Parses crontab file format. + */ + friend std::istream& operator >> (std::istream& inputStream, CTCron& cron); + +/** + * Tokenizes to crontab file format. + */ + friend std::ostream& operator << (std::ostream& outputStream, const CTCron& cron); + +/** + * Apply changes. + */ + void apply(); + +/** + * Cancel changes. + */ + void cancel(); + +/** + * Indicates whether or not dirty. + */ + bool dirty(); + +/** + * Returns the PATH environment variable value. A short cut to iterating + * the tasks vector. + */ + std::string path() const; + + /** + * Returns whether an error has occured + */ + bool isError() { return !error.isEmpty(); } + + /** + * Return error description + */ + QString errorMessage() { QString r = error; error = QString::null; return r; } + + +/** + * Indicates whether or not the crontab belongs to the system. + */ + const bool syscron; + +/** + * User login. + */ + std::string login; + +/** + * User real name. + */ + std::string name; + +/** + * User's scheduled tasks. + */ + std::vector task; + +/** + * User's environment variables. Note: These are only environment variables + * found in the user's crontab file and does not include any set in a + * login or shell script such as ".bash_profile". + */ + std::vector variable; + +/** + * Destructor. + */ + ~CTCron(); + +private: + +/** + * Can't copy a user! + */ + CTCron(const CTCron& source); + + unsigned int initialTaskCount; + unsigned int initialVariableCount; + QString writeCommand; + QString tmpFileName; + + QString error; + +protected: + // Initialize member variables from the struct passwd. + bool initFromPasswd(const struct passwd *); +}; + +typedef std::vector::iterator CTTaskIterator; +typedef std::vector::iterator CTVariableIterator; + +#endif // CTCRON_H -- cgit v1.2.1