00001 00003 00016 #ifndef _USERTABLE_H_ 00017 #define _USERTABLE_H_ 00018 00019 #include <map> 00020 #include <deque> 00021 00022 #include "inotify-cxx.h" 00023 #include "incrontab.h" 00024 00025 00026 class UserTable; 00027 00029 typedef void (*proc_done_cb)(InotifyWatch*); 00030 00032 typedef struct 00033 { 00034 pid_t pid; 00035 proc_done_cb onDone; 00036 InotifyWatch* pWatch; 00037 } ProcData_t; 00038 00040 typedef std::map<InotifyWatch*, UserTable*> IWUT_MAP; 00041 00043 typedef std::map<InotifyWatch*, InCronTabEntry*> IWCE_MAP; 00044 00046 typedef std::deque<ProcData_t> PROC_LIST; 00047 00049 00052 class EventDispatcher 00053 { 00054 public: 00056 00059 EventDispatcher(Inotify* pIn); 00060 00062 ~EventDispatcher() {} 00063 00065 00068 void DispatchEvent(InotifyEvent& rEvt); 00069 00071 00075 void Register(InotifyWatch* pWatch, UserTable* pTab); 00076 00078 00081 void Unregister(InotifyWatch* pWatch); 00082 00084 00087 void UnregisterAll(UserTable* pTab); 00088 00089 private: 00090 Inotify* m_pIn; 00091 IWUT_MAP m_maps; 00092 00094 00098 UserTable* FindTable(InotifyWatch* pW); 00099 }; 00100 00101 00103 00108 class UserTable 00109 { 00110 public: 00112 00117 UserTable(Inotify* pIn, EventDispatcher* pEd, const std::string& rUser); 00118 00120 virtual ~UserTable(); 00121 00123 00128 void Load(); 00129 00131 00135 void Dispose(); 00136 00138 00141 void OnEvent(InotifyEvent& rEvt); 00142 00144 00148 static void FinishDone(); 00149 00151 00158 bool MayAccess(const std::string& rPath, bool fNoFollow) const; 00159 00160 private: 00161 Inotify* m_pIn; 00162 EventDispatcher* m_pEd; 00163 std::string m_user; 00164 InCronTab m_tab; 00165 IWCE_MAP m_map; 00166 00167 static PROC_LIST s_procList; 00168 00170 00174 InCronTabEntry* FindEntry(InotifyWatch* pWatch); 00175 00177 00183 bool PrepareArgs(const std::string& rCmd, int& argc, char**& argv); 00184 00186 00190 void CleanupArgs(int argc, char** argv); 00191 00192 }; 00193 00194 #endif //_USERTABLE_H_