]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/transport.h
Add initial query support to m_mysql [patch by Athenon]
[user/henk/code/inspircd.git] / src / modules / transport.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __TRANSPORT_H__
15 #define __TRANSPORT_H__
16
17 #include <map>
18 #include <string>
19
20 /** ssl_cert is a class which abstracts SSL certificate
21  * and key information.
22  *
23  * Because gnutls and openssl represent key information in
24  * wildly different ways, this class allows it to be accessed
25  * in a unified manner. These classes are attached to ssl-
26  * connected local users using Extensible::Extend() and the
27  * key 'ssl_cert'.
28  */
29 class ssl_cert
30 {
31  public:
32         std::string dn;
33         std::string issuer;
34         std::string error;
35         std::string fingerprint;
36         bool trusted, invalid, unknownsigner, revoked;
37
38         /** Get certificate distinguished name
39          * @return Certificate DN
40          */
41         const std::string& GetDN()
42         {
43                 return dn;
44         }
45
46         /** Get Certificate issuer
47          * @return Certificate issuer
48          */
49         const std::string& GetIssuer()
50         {
51                 return issuer;
52         }
53
54         /** Get error string if an error has occured
55          * @return The error associated with this users certificate,
56          * or an empty string if there is no error.
57          */
58         const std::string& GetError()
59         {
60                 return error;
61         }
62
63         /** Get key fingerprint.
64          * @return The key fingerprint as a hex string.
65          */
66         const std::string& GetFingerprint()
67         {
68                 return fingerprint;
69         }
70
71         /** Get trust status
72          * @return True if this is a trusted certificate
73          * (the certificate chain validates)
74          */
75         bool IsTrusted()
76         {
77                 return trusted;
78         }
79
80         /** Get validity status
81          * @return True if the certificate itself is
82          * correctly formed.
83          */
84         bool IsInvalid()
85         {
86                 return invalid;
87         }
88
89         /** Get signer status
90          * @return True if the certificate appears to be
91          * self-signed.
92          */
93         bool IsUnknownSigner()
94         {
95                 return unknownsigner;
96         }
97
98         /** Get revokation status.
99          * @return True if the certificate is revoked.
100          * Note that this only works properly for GnuTLS
101          * right now.
102          */
103         bool IsRevoked()
104         {
105                 return revoked;
106         }
107
108         std::string GetMetaLine()
109         {
110                 std::stringstream value;
111                 bool hasError = error.length();
112                 value << (IsInvalid() ? "v" : "V") << (IsTrusted() ? "T" : "t") << (IsRevoked() ? "R" : "r")
113                         << (IsUnknownSigner() ? "s" : "S") << (hasError ? "E" : "e") << " ";
114                 if (hasError)
115                         value << GetError();
116                 else
117                         value << GetFingerprint() << " " << GetDN() << " " << GetIssuer();
118                 return value.str();
119         }
120 };
121
122 /** Used to represent a request to a transport provider module
123  */
124 class ISHRequest : public Request
125 {
126  public:
127         BufferedSocket* Sock;
128
129         ISHRequest(Module* Me, Module* Target, const char* rtype, BufferedSocket* sock) : Request(Me, Target, rtype), Sock(sock)
130         {
131         }
132 };
133
134 /** Used to represent a request to attach a cert to an BufferedSocket
135  */
136 class BufferedSocketAttachCertRequest : public ISHRequest
137 {
138  public:
139         /** Initialize the request as an attach cert message */
140         BufferedSocketAttachCertRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_ATTACH", is)
141         {
142         }
143 };
144
145 /** Used to check if a handshake is complete on an BufferedSocket yet
146  */
147 class BufferedSocketHSCompleteRequest : public ISHRequest
148 {
149  public:
150         /** Initialize the request as a 'handshake complete?' message */
151         BufferedSocketHSCompleteRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_HSDONE", is)
152         {
153         }
154 };
155
156 /** Used to hook a transport provider to an BufferedSocket
157  */
158 class BufferedSocketHookRequest : public ISHRequest
159 {
160  public:
161         /** Initialize request as a hook message */
162         BufferedSocketHookRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_HOOK", is)
163         {
164         }
165 };
166
167 /** Used to unhook a transport provider from an BufferedSocket
168  */
169 class BufferedSocketUnhookRequest : public ISHRequest
170 {
171  public:
172         /** Initialize request as an unhook message */
173         BufferedSocketUnhookRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_UNHOOK", is)
174         {
175         }
176 };
177
178 class BufferedSocketNameRequest : public ISHRequest
179 {
180  public:
181         /** Initialize request as a get name message */
182         BufferedSocketNameRequest(Module* Me, Module* Target) : ISHRequest(Me, Target, "IS_NAME", NULL)
183         {
184         }
185 };
186
187 class BufferedSocketFingerprintRequest : public ISHRequest
188 {
189  public:
190         /** Initialize request as a fingerprint message */
191         BufferedSocketFingerprintRequest(BufferedSocket* is, Module* Me, Module* Target) : ISHRequest(Me, Target, "GET_FP", is)
192         {
193         }
194 };
195
196 #endif