Subversion Repositories public

Rev

Rev 45 | Rev 55 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 45 Rev 47
Line 20... Line 20...
20
#include <string>
20
#include <string>
21
#include <deque>
21
#include <deque>
22
22
23
#include "strtok.h"
23
#include "strtok.h"
24
24
25
-
 
-
 
25
/// Incron table base directory
26
#define INCRON_TABLE_BASE "/var/spool/incron/"
26
#define INCRON_TABLE_BASE "/var/spool/incron/"
27
27
28
28
29
-
 
-
 
29
/// Incron table entry class.
30
class InCronTabEntry
30
class InCronTabEntry
31
{
31
{
32
public:
32
public:
-
 
33
  /// Constructor.
-
 
34
  /**
-
 
35
   * Creates an empty entry for later use with Parse().
-
 
36
   *
-
 
37
   * \sa Parse()
-
 
38
   */
33
  InCronTabEntry();
39
  InCronTabEntry();
34
40
-
 
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
   */
35
  InCronTabEntry(const std::string& rPath, uint32_t uMask, const std::string& rCmd);
49
  InCronTabEntry(const std::string& rPath, uint32_t uMask, const std::string& rCmd);
36
 
50
 
-
 
51
  /// Destructor.
37
  ~InCronTabEntry() {}
52
  ~InCronTabEntry() {}
38
 
53
 
-
 
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
   */
39
  std::string ToString() const;
60
  std::string ToString() const;
40
 
61
 
-
 
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
   */
41
  static bool Parse(const std::string& rStr, InCronTabEntry& rEntry);
68
  static bool Parse(const std::string& rStr, InCronTabEntry& rEntry);
42
 
69
 
-
 
70
  /// Returns the watch filesystem path.
-
 
71
  /**
-
 
72
   * \return watch path
-
 
73
   */
43
  inline const std::string& GetPath() const
74
  inline const std::string& GetPath() const
44
  {
75
  {
45
    return m_path;
76
    return m_path;
46
  }
77
  }
47
 
78
 
-
 
79
  /// Returns the event mask.
-
 
80
  /**
-
 
81
   * \return event mask
-
 
82
   */
48
  inline int32_t GetMask() const
83
  inline int32_t GetMask() const
49
  {
84
  {
50
    return m_uMask;
85
    return m_uMask;
51
  }
86
  }
52
 
87
 
-
 
88
  /// Returns the command string.
-
 
89
  /**
-
 
90
   * \return command string
-
 
91
   */
53
  inline const std::string& GetCmd() const
92
  inline const std::string& GetCmd() const
54
  {
93
  {
55
    return m_cmd;
94
    return m_cmd;
56
  }
95
  }
57
 
96
 
-
 
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
 
58
protected:
106
protected:
59
  std::string m_path;
107
  std::string m_path; ///< watch path
60
  uint32_t m_uMask;
108
  uint32_t m_uMask;   ///< event mask
61
  std::string m_cmd;
109
  std::string m_cmd;  ///< command string
-
 
110
  bool m_fNoLoop;     ///< no loop yes/no
62
};
111
};
63
112
64
113
65
-
 
-
 
114
/// Incron table class.
66
class InCronTab
115
class InCronTab
67
{
116
{
68
public:
117
public:
-
 
118
  /// Constructor.
69
  InCronTab() {}
119
  InCronTab() {}
70
 
120
 
-
 
121
  /// Destructor.
71
  ~InCronTab() {}
122
  ~InCronTab() {}
72
 
123
 
-
 
124
  /// Add an entry to the table.
-
 
125
  /**
-
 
126
   * \param[in] rEntry table entry
-
 
127
   */
73
  inline void Add(const InCronTabEntry& rEntry)
128
  inline void Add(const InCronTabEntry& rEntry)
74
  {
129
  {
75
    m_tab.push_back(rEntry);
130
    m_tab.push_back(rEntry);
76
  }
131
  }
77
 
132
 
-
 
133
  /// Removes all entries.
78
  inline void Clear()
134
  inline void Clear()
79
  {
135
  {
80
    m_tab.clear();
136
    m_tab.clear();
81
  }
137
  }
82
 
138
 
-
 
139
  /// Checks whether the table is empty.
-
 
140
  /**
-
 
141
   * \return true = empty, false = otherwise
-
 
142
   */
83
  inline bool IsEmpty() const
143
  inline bool IsEmpty() const
84
  {
144
  {
85
    return m_tab.empty();
145
    return m_tab.empty();
86
  }
146
  }
87
 
147
 
-
 
148
  /// Returns the count of entries.
-
 
149
  /**
-
 
150
   * \return count of entries
-
 
151
   */
88
  inline int GetCount() const
152
  inline int GetCount() const
89
  {
153
  {
90
    return (int) m_tab.size();
154
    return (int) m_tab.size();
91
  }
155
  }
92
 
156
 
-
 
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
   */
93
  inline InCronTabEntry& GetEntry(int index)
165
  inline InCronTabEntry& GetEntry(int index)
94
  {
166
  {
95
    return m_tab[index];
167
    return m_tab[index];
96
  }
168
  }
97
 
169
 
-
 
170
  /// Loads the table.
-
 
171
  /**
-
 
172
   * \param[in] rPath path to a source table file
-
 
173
   * \return true = success, false = failure
-
 
174
   */
98
  bool Load(const std::string& rPath);
175
  bool Load(const std::string& rPath);
99
 
176
 
-
 
177
  /// Saves the table.
-
 
178
  /**
-
 
179
   * \param[in] rPath path to a destination table file
-
 
180
   * \return true = success, false = failure
-
 
181
   */
100
  bool Save(const std::string& rPath);
182
  bool Save(const std::string& rPath);
101
 
183
 
-
 
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
   */
102
  static bool CheckUser(const std::string& rUser);
189
  static bool CheckUser(const std::string& rUser);
103
 
190
 
-
 
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
   */
104
  static std::string GetUserTablePath(const std::string& rUser);
198
  static std::string GetUserTablePath(const std::string& rUser);
105
199
106
protected:
200
protected:
107
  std::deque<InCronTabEntry> m_tab;
201
  std::deque<InCronTabEntry> m_tab; ///< incron table
108
};
202
};
109
203
110
204
111
#endif //_INCRONTAB_H_
205
#endif //_INCRONTAB_H_