Subversion Repositories public

Rev

Rev 45 | Rev 55 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
45 luk 1
 
2
/// inotify cron table manipulator classes header
3
/**
4
 * \file incrontab.h
5
 *
6
 * inotify cron system
7
 *
8
 * Copyright (C) 2006 Lukas Jelinek, <lukas@aiken.cz>
9
 *
10
 * This program is free software; you can use it, redistribute
11
 * it and/or modify it under the terms of the GNU General Public
12
 * License, version 2 (see LICENSE-GPL).
13
 *  
14
 */
15
 
16
 
17
#ifndef _INCRONTAB_H_
18
#define _INCRONTAB_H_
19
 
20
#include <string>
21
#include <deque>
22
 
23
#include "strtok.h"
24
 
47 luk 25
/// Incron table base directory
45 luk 26
#define INCRON_TABLE_BASE "/var/spool/incron/"
27
 
28
 
47 luk 29
/// Incron table entry class.
45 luk 30
class InCronTabEntry
31
{
32
public:
47 luk 33
  /// Constructor.
34
  /**
35
   * Creates an empty entry for later use with Parse().
36
   *
37
   * \sa Parse()
38
   */
45 luk 39
  InCronTabEntry();
40
 
47 luk 41
  /// Constructor.
42
  /**
43
   * Creates an entry based on defined parameters.
44
   *
45
   * \param[in] rPath watched filesystem path
46
   * \param[in] uMask event mask
47
   * \param[in] rCmd command string
48
   */
45 luk 49
  InCronTabEntry(const std::string& rPath, uint32_t uMask, const std::string& rCmd);
50
 
47 luk 51
  /// Destructor.
45 luk 52
  ~InCronTabEntry() {}
53
 
47 luk 54
  /// Converts the entry to string representation.
55
  /**
56
   * This method creates a string for use in a table file.
57
   *
58
   * \return string representation
59
   */
45 luk 60
  std::string ToString() const;
61
 
47 luk 62
  /// Parses a string and attempts to extract entry parameters.
63
  /**
64
   * \param[in] rStr parsed string
65
   * \param[out] rEntry parametrized entry
66
   * \return true = success, false = failure
67
   */
45 luk 68
  static bool Parse(const std::string& rStr, InCronTabEntry& rEntry);
69
 
47 luk 70
  /// Returns the watch filesystem path.
71
  /**
72
   * \return watch path
73
   */
45 luk 74
  inline const std::string& GetPath() const
75
  {
76
    return m_path;
77
  }
78
 
47 luk 79
  /// Returns the event mask.
80
  /**
81
   * \return event mask
82
   */
45 luk 83
  inline int32_t GetMask() const
84
  {
85
    return m_uMask;
86
  }
87
 
47 luk 88
  /// Returns the command string.
89
  /**
90
   * \return command string
91
   */
45 luk 92
  inline const std::string& GetCmd() const
93
  {
94
    return m_cmd;
95
  }
96
 
47 luk 97
  /// Checks whether this entry has set loop-avoidance.
98
  /**
99
   * \return true = no loop, false = loop allowed
100
   */
101
  inline bool IsNoLoop() const
102
  {
103
    return m_fNoLoop;
104
  }
105
 
45 luk 106
protected:
47 luk 107
  std::string m_path; ///< watch path
108
  uint32_t m_uMask;   ///< event mask
109
  std::string m_cmd;  ///< command string
110
  bool m_fNoLoop;     ///< no loop yes/no
45 luk 111
};
112
 
113
 
47 luk 114
/// Incron table class.
45 luk 115
class InCronTab
116
{
117
public:
47 luk 118
  /// Constructor.
45 luk 119
  InCronTab() {}
120
 
47 luk 121
  /// Destructor.
45 luk 122
  ~InCronTab() {}
123
 
47 luk 124
  /// Add an entry to the table.
125
  /**
126
   * \param[in] rEntry table entry
127
   */
45 luk 128
  inline void Add(const InCronTabEntry& rEntry)
129
  {
130
    m_tab.push_back(rEntry);
131
  }
132
 
47 luk 133
  /// Removes all entries.
45 luk 134
  inline void Clear()
135
  {
136
    m_tab.clear();
137
  }
138
 
47 luk 139
  /// Checks whether the table is empty.
140
  /**
141
   * \return true = empty, false = otherwise
142
   */
45 luk 143
  inline bool IsEmpty() const
144
  {
145
    return m_tab.empty();
146
  }
147
 
47 luk 148
  /// Returns the count of entries.
149
  /**
150
   * \return count of entries
151
   */
45 luk 152
  inline int GetCount() const
153
  {
154
    return (int) m_tab.size();
155
  }
156
 
47 luk 157
  /// Returns an entry.
158
  /**
159
   * \return reference to the entry for the given index
160
   *
161
   * \attention This method doesn't test index bounds. If you
162
   *            pass an invalid value the program may crash
163
   *            and/or behave unpredictible way!
164
   */
45 luk 165
  inline InCronTabEntry& GetEntry(int index)
166
  {
167
    return m_tab[index];
168
  }
169
 
47 luk 170
  /// Loads the table.
171
  /**
172
   * \param[in] rPath path to a source table file
173
   * \return true = success, false = failure
174
   */
45 luk 175
  bool Load(const std::string& rPath);
176
 
47 luk 177
  /// Saves the table.
178
  /**
179
   * \param[in] rPath path to a destination table file
180
   * \return true = success, false = failure
181
   */
45 luk 182
  bool Save(const std::string& rPath);
183
 
47 luk 184
  /// Checks whether an user has permission to use incron.
185
  /**
186
   * \param[in] rUser user name
187
   * \return true = permission OK, false = otherwise
188
   */
45 luk 189
  static bool CheckUser(const std::string& rUser);
190
 
47 luk 191
  /// Composes a path to an user incron table file.
192
  /**
193
   * \param[in] rUser user name
194
   * \return path to the table file
195
   *
196
   * \attention No tests (existence, permission etc.) are done.
197
   */
45 luk 198
  static std::string GetUserTablePath(const std::string& rUser);
199
 
200
protected:
47 luk 201
  std::deque<InCronTabEntry> m_tab; ///< incron table
45 luk 202
};
203
 
204
 
205
#endif //_INCRONTAB_H_