~ubuntu-branches/ubuntu/quantal/znc/quantal-backports

« back to all changes in this revision

Viewing changes to include/znc/IRCSock.h

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2013-01-01 19:39:47 UTC
  • mfrom: (21.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130101193947-zlqyse3v2mjxnhvw
Tags: 1.0-2~ubuntu12.10.1
No-change backport to quantal (LP: #1085731)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004-2012  See the AUTHORS file for details.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 2 as published
 
6
 * by the Free Software Foundation.
 
7
 */
 
8
 
 
9
#ifndef _IRCSOCK_H
 
10
#define _IRCSOCK_H
 
11
 
 
12
#include <znc/zncconfig.h>
 
13
#include <znc/Socket.h>
 
14
#include <znc/Nick.h>
 
15
 
 
16
#include <deque>
 
17
 
 
18
// Forward Declarations
 
19
class CChan;
 
20
class CUser;
 
21
class CIRCNetwork;
 
22
class CClient;
 
23
// !Forward Declarations
 
24
 
 
25
class CIRCSock : public CZNCSock {
 
26
public:
 
27
        CIRCSock(CIRCNetwork* pNetwork);
 
28
        virtual ~CIRCSock();
 
29
 
 
30
        typedef enum {
 
31
                // These values must line up with their position in the CHANMODE argument to raw 005
 
32
                ListArg    = 0,
 
33
                HasArg     = 1,
 
34
                ArgWhenSet = 2,
 
35
                NoArg      = 3
 
36
        } EChanModeArgs;
 
37
 
 
38
        // Message Handlers
 
39
        bool OnCTCPReply(CNick& Nick, CString& sMessage);
 
40
        bool OnPrivCTCP(CNick& Nick, CString& sMessage);
 
41
        bool OnChanCTCP(CNick& Nick, const CString& sChan, CString& sMessage);
 
42
        bool OnGeneralCTCP(CNick& Nick, CString& sMessage);
 
43
        bool OnPrivMsg(CNick& Nick, CString& sMessage);
 
44
        bool OnChanMsg(CNick& Nick, const CString& sChan, CString& sMessage);
 
45
        bool OnPrivNotice(CNick& Nick, CString& sMessage);
 
46
        bool OnChanNotice(CNick& Nick, const CString& sChan, CString& sMessage);
 
47
        bool OnServerCapAvailable(const CString& sCap);
 
48
        // !Message Handlers
 
49
 
 
50
        virtual void ReadLine(const CString& sData);
 
51
        virtual void Connected();
 
52
        virtual void Disconnected();
 
53
        virtual void ConnectionRefused();
 
54
        virtual void SockError(int iErrno, const CString& sDescription);
 
55
        virtual void Timeout();
 
56
        virtual void ReachedMaxBuffer();
 
57
 
 
58
        void PutIRC(const CString& sLine);
 
59
        void PutIRCQuick(const CString& sLine); //!< Should be used for PONG only
 
60
        void ResetChans();
 
61
        void Quit(const CString& sQuitMsg = "");
 
62
 
 
63
        /** You can call this from CModule::OnServerCapResult to suspend
 
64
         *  sending other CAP requests and CAP END for a while. Each
 
65
         *  call to PauseCap should be balanced with a call to ResumeCap.
 
66
         */
 
67
        void PauseCap();
 
68
        /** If you used PauseCap, call this when CAP negotiation and logging in
 
69
         *  should be resumed again.
 
70
         */
 
71
        void ResumeCap();
 
72
 
 
73
        // Setters
 
74
        void SetPass(const CString& s) { m_sPass = s; }
 
75
        // !Setters
 
76
 
 
77
        // Getters
 
78
        unsigned int GetMaxNickLen() const { return m_uMaxNickLen; }
 
79
        EChanModeArgs GetModeType(unsigned char uMode) const;
 
80
        unsigned char GetPermFromMode(unsigned char uMode) const;
 
81
        const std::map<unsigned char, EChanModeArgs>& GetChanModes() const { return m_mueChanModes; }
 
82
        bool IsPermChar(const char c) const { return (c != '\0' && GetPerms().find(c) != CString::npos); }
 
83
        bool IsPermMode(const char c) const { return (c != '\0' && GetPermModes().find(c) != CString::npos); }
 
84
        const CString& GetPerms() const { return m_sPerms; }
 
85
        const CString& GetPermModes() const { return m_sPermModes; }
 
86
        CString GetNickMask() const { return m_Nick.GetNickMask(); }
 
87
        const CString& GetNick() const { return m_Nick.GetNick(); }
 
88
        const CString& GetPass() const { return m_sPass; }
 
89
        CIRCNetwork* GetNetwork() const { return m_pNetwork; }
 
90
        bool HasNamesx() const { return m_bNamesx; }
 
91
        bool HasUHNames() const { return m_bUHNames; }
 
92
        const std::set<unsigned char>& GetUserModes() const { return m_scUserModes; }
 
93
        // This is true if we are past raw 001
 
94
        bool IsAuthed() const { return m_bAuthed; }
 
95
        bool IsCapAccepted(const CString& sCap) { return 1 == m_ssAcceptedCaps.count(sCap); }
 
96
        const MCString& GetISupport() const { return m_mISupport; }
 
97
        // !Getters
 
98
 
 
99
        // This handles NAMESX and UHNAMES in a raw 353 reply
 
100
        void ForwardRaw353(const CString& sLine) const;
 
101
        void ForwardRaw353(const CString& sLine, CClient* pClient) const;
 
102
 
 
103
        // TODO move this function to CIRCNetwork and make it non-static?
 
104
        static bool IsFloodProtected(double fRate);
 
105
private:
 
106
        void SetNick(const CString& sNick);
 
107
        void ParseISupport(const CString& sLine);
 
108
        // This is called when we connect and the nick we want is already taken
 
109
        void SendAltNick(const CString& sBadNick);
 
110
        void SendNextCap();
 
111
        void TrySend();
 
112
protected:
 
113
        bool                                m_bAuthed;
 
114
        bool                                m_bNamesx;
 
115
        bool                                m_bUHNames;
 
116
        CString                             m_sPerms;
 
117
        CString                             m_sPermModes;
 
118
        std::set<unsigned char>             m_scUserModes;
 
119
        std::map<unsigned char, EChanModeArgs>   m_mueChanModes;
 
120
        CIRCNetwork*                        m_pNetwork;
 
121
        CNick                               m_Nick;
 
122
        CString                             m_sPass;
 
123
        std::map<CString, CChan*>           m_msChans;
 
124
        unsigned int                        m_uMaxNickLen;
 
125
        unsigned int                        m_uCapPaused;
 
126
        SCString                            m_ssAcceptedCaps;
 
127
        SCString                            m_ssPendingCaps;
 
128
        time_t                              m_lastCTCP;
 
129
        unsigned int                        m_uNumCTCP;
 
130
        static const time_t                 m_uCTCPFloodTime;
 
131
        static const unsigned int           m_uCTCPFloodCount;
 
132
        MCString                            m_mISupport;
 
133
        std::deque<CString>                 m_vsSendQueue;
 
134
        short int                           m_iSendsAllowed;
 
135
        unsigned short int                  m_uFloodBurst;
 
136
        double                              m_fFloodRate;
 
137
        bool                                m_bFloodProtection;
 
138
 
 
139
        friend class CIRCFloodTimer;
 
140
};
 
141
 
 
142
#endif // !_IRCSOCK_H