00001 00003 00017 #ifndef _INCRONTAB_H_ 00018 #define _INCRONTAB_H_ 00019 00020 #include <string> 00021 #include <deque> 00022 00023 #include "strtok.h" 00024 00026 #define INCRON_USER_TABLE_BASE "/var/spool/incron/" 00027 00029 #define INCRON_SYS_TABLE_BASE "/etc/incron.d/" 00030 00031 00033 class InCronTabEntry 00034 { 00035 public: 00037 00042 InCronTabEntry(); 00043 00045 00052 InCronTabEntry(const std::string& rPath, uint32_t uMask, const std::string& rCmd); 00053 00055 ~InCronTabEntry() {} 00056 00058 00063 std::string ToString() const; 00064 00066 00071 static bool Parse(const std::string& rStr, InCronTabEntry& rEntry); 00072 00074 00077 inline const std::string& GetPath() const 00078 { 00079 return m_path; 00080 } 00081 00083 00086 inline int32_t GetMask() const 00087 { 00088 return m_uMask; 00089 } 00090 00092 00095 inline const std::string& GetCmd() const 00096 { 00097 return m_cmd; 00098 } 00099 00101 00104 inline bool IsNoLoop() const 00105 { 00106 return m_fNoLoop; 00107 } 00108 00110 00122 static std::string GetSafePath(const std::string& rPath); 00123 00124 protected: 00125 std::string m_path; 00126 uint32_t m_uMask; 00127 std::string m_cmd; 00128 bool m_fNoLoop; 00129 }; 00130 00131 00133 class InCronTab 00134 { 00135 public: 00137 InCronTab() {} 00138 00140 ~InCronTab() {} 00141 00143 00146 inline void Add(const InCronTabEntry& rEntry) 00147 { 00148 m_tab.push_back(rEntry); 00149 } 00150 00152 inline void Clear() 00153 { 00154 m_tab.clear(); 00155 } 00156 00158 00161 inline bool IsEmpty() const 00162 { 00163 return m_tab.empty(); 00164 } 00165 00167 00170 inline int GetCount() const 00171 { 00172 return (int) m_tab.size(); 00173 } 00174 00176 00183 inline InCronTabEntry& GetEntry(int index) 00184 { 00185 return m_tab[index]; 00186 } 00187 00189 00193 bool Load(const std::string& rPath); 00194 00196 00200 bool Save(const std::string& rPath); 00201 00203 00207 static bool CheckUser(const std::string& rUser); 00208 00210 00216 static std::string GetUserTablePath(const std::string& rUser); 00217 00219 00225 static std::string GetSystemTablePath(const std::string& rName); 00226 00227 protected: 00228 std::deque<InCronTabEntry> m_tab; 00229 }; 00230 00231 00232 #endif //_INCRONTAB_H_