~jdong/+junk/znc

« back to all changes in this revision

Viewing changes to znc.h

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2008-12-06 23:28:22 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081206232822-6n1lkcot8o78bk9f
Tags: 0.062-2
* Add missing ${misc:Depends}. Thanks lintian.
* Fix debian/watch, so that it does not take the new znc-extra tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
100
100
        bool DeletePidFile();
101
101
        CUser* GetUser(const CString& sUser);
102
102
        Csock* FindSockByName(const CString& sSockName);
103
 
        bool IsHostAllowed(const CString& sHostMask);
 
103
        bool IsHostAllowed(const CString& sHostMask) const;
104
104
        void InitDirs(const CString& sArgvPath, const CString& sDataDir);
105
105
        bool OnBoot();
106
106
        CString ExpandConfigPath(const CString& sConfigFile);
107
 
        bool WriteNewConfig(const CString& sConfig);
 
107
        bool WriteNewConfig(CString& sConfigFile);
108
108
        bool WriteConfig();
109
109
        bool ParseConfig(const CString& sConfig);
110
110
        bool RehashConfig(CString& sError);
111
111
        static CString GetVersion();
112
112
        static CString GetTag(bool bIncludeVersion = true);
113
 
        CString GetUptime();
 
113
        CString GetUptime() const;
114
114
        // This returns the path to the .so and to the data dir
115
115
        // which is where static data (webadmin skins) are saved
116
116
        bool FindModPath(const CString& sModule, CString& sModPath,
139
139
        // !Setters
140
140
 
141
141
        // Getters
142
 
        bool GetNeedRehash() { return m_bNeedRehash; }
 
142
        bool GetNeedRehash() const { return m_bNeedRehash; }
143
143
        CSockManager& GetManager() { return m_Manager; }
144
144
#ifdef _MODULES
145
145
        CGlobalModules& GetModules() { return *m_pModules; }
180
180
        // This creates a CConnectUserTimer if we haven't got one yet
181
181
        void EnableConnectUser();
182
182
        void DisableConnectUser();
183
 
        // This needs to be called if anything was added / removed to m_msUsers
184
 
        void RestartConnectUser();
185
183
 
186
184
private:
187
185
        bool DoRehash(CString& sError);
225
223
        CConnectUserTimer               *m_pConnectUserTimer;
226
224
};
227
225
 
 
226
class CRealListener : public Csock {
 
227
public:
 
228
        CRealListener() : Csock() {}
 
229
        ~CRealListener() {}
 
230
 
 
231
        virtual bool ConnectionFrom(const CString& sHost, unsigned short uPort) {
 
232
                DEBUG_ONLY(cout << GetSockName() << " == ConnectionFrom(" << sHost << ", " << uPort << ")" << endl);
 
233
                return CZNC::Get().IsHostAllowed(sHost);
 
234
        }
 
235
 
 
236
        virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort) {
 
237
                CClient *pClient = new CClient(sHost, uPort);
 
238
#ifdef _MODULES
 
239
                CZNC::Get().GetModules().OnClientConnect(pClient, sHost, uPort);
 
240
#endif
 
241
                return pClient;
 
242
        }
 
243
 
 
244
        virtual void SockError(int iErrno) {
 
245
                DEBUG_ONLY(cout << GetSockName() << " == SockError(" << strerror(iErrno) << ")" << endl);
 
246
                if (iErrno == EMFILE) {
 
247
                        // We have too many open fds, let's close this listening port to be able to continue
 
248
                        // to work, next rehash will (try to) reopen it.
 
249
                        Close();
 
250
                }
 
251
        }
 
252
};
 
253
 
228
254
class CListener {
229
255
public:
230
256
        CListener(unsigned short uPort, const CString& sBindHost, bool bSSL, bool bIPV6) {
232
258
                m_sBindHost = sBindHost;
233
259
                m_bSSL = bSSL;
234
260
                m_bIPV6 = bIPV6;
235
 
                m_pClient = NULL;
 
261
                m_pListener = NULL;
236
262
        }
237
263
 
238
264
        virtual ~CListener() {
239
 
                if (m_pClient)
240
 
                        CZNC::Get().GetManager().DelSockByAddr(m_pClient);
 
265
                if (m_pListener)
 
266
                        CZNC::Get().GetManager().DelSockByAddr(m_pListener);
241
267
        }
242
268
 
243
269
        // Setters
255
281
        // !Getters
256
282
 
257
283
        bool Listen() {
258
 
                if (!m_uPort || m_pClient) {
 
284
                if (!m_uPort || m_pListener) {
259
285
                        return false;
260
286
                }
261
287
 
262
 
                m_pClient = new CClient;
 
288
                m_pListener = new CRealListener;
263
289
 
264
290
                bool bSSL = false;
265
291
#ifdef HAVE_LIBSSL
266
292
                if (IsSSL()) {
267
293
                        bSSL = true;
268
 
                        m_pClient->SetPemLocation(CZNC::Get().GetPemLocation());
 
294
                        m_pListener->SetPemLocation(CZNC::Get().GetPemLocation());
269
295
                }
270
296
#endif
271
297
 
272
 
                return CZNC::Get().GetManager().ListenHost(m_uPort, "_LISTENER", m_sBindHost, bSSL, SOMAXCONN, m_pClient, 0, m_bIPV6);
 
298
                return CZNC::Get().GetManager().ListenHost(m_uPort, "_LISTENER", m_sBindHost, bSSL, SOMAXCONN,
 
299
                                m_pListener, 0, m_bIPV6);
273
300
        }
274
301
private:
275
302
protected:
277
304
        bool                    m_bIPV6;
278
305
        unsigned short  m_uPort;
279
306
        CString                 m_sBindHost;
280
 
        CClient*                m_pClient;
 
307
        CRealListener*          m_pListener;
281
308
};
282
309
 
283
310
#endif // !_ZNC_H