1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>InspIRCd: users.cpp Source File</title>
<link href="inspircd.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.3 -->
<div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div>
<h1>users.cpp</h1><a href="users_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/* +------------------------------------+</span>
00002 <span class="comment"> * | Inspire Internet Relay Chat Daemon |</span>
00003 <span class="comment"> * +------------------------------------+</span>
00004 <span class="comment"> *</span>
00005 <span class="comment"> * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.</span>
00006 <span class="comment"> * E-mail:</span>
00007 <span class="comment"> * <brain@chatspike.net></span>
00008 <span class="comment"> * <Craig@chatspike.net></span>
00009 <span class="comment"> * </span>
00010 <span class="comment"> * Written by Craig Edwards, Craig McLure, and others.</span>
00011 <span class="comment"> * This program is free but copyrighted software; see</span>
00012 <span class="comment"> * the file COPYING for details.</span>
00013 <span class="comment"> *</span>
00014 <span class="comment"> * ---------------------------------------------------</span>
00015 <span class="comment"> */</span>
00016
00017 <span class="preprocessor">#include "inspircd_config.h"</span>
00018 <span class="preprocessor">#include "<a class="code" href="channels_8h.html">channels.h</a>"</span>
00019 <span class="preprocessor">#include "<a class="code" href="users_8h.html">users.h</a>"</span>
00020 <span class="preprocessor">#include "inspircd.h"</span>
00021 <span class="preprocessor">#include <stdio.h></span>
00022 <span class="preprocessor">#include "inspstring.h"</span>
00023
<a name="l00024"></a><a class="code" href="users_8cpp.html#a0">00024</a> <span class="keyword">extern</span> std::stringstream <a class="code" href="channels_8cpp.html#a34">config_f</a>;
00025
<a name="l00026"></a><a class="code" href="users_8cpp.html#a1">00026</a> <span class="keyword">extern</span> time_t <a class="code" href="channels_8cpp.html#a37">TIME</a>;
00027
<a name="l00028"></a><a class="code" href="classuserrec.html#a0">00028</a> <a class="code" href="classuserrec.html#a0">userrec::userrec</a>()
00029 {
00030 <span class="comment">// the PROPER way to do it, AVOID bzero at *ALL* costs</span>
00031 strcpy(<a class="code" href="classuserrec.html#o0">nick</a>,<span class="stringliteral">""</span>);
00032 strcpy(<a class="code" href="classconnection.html#o2">ip</a>,<span class="stringliteral">"127.0.0.1"</span>);
00033 <a class="code" href="classuserrec.html#o10">timeout</a> = 0;
00034 strcpy(<a class="code" href="classuserrec.html#o1">ident</a>,<span class="stringliteral">""</span>);
00035 strcpy(<a class="code" href="classconnection.html#o1">host</a>,<span class="stringliteral">""</span>);
00036 strcpy(<a class="code" href="classuserrec.html#o2">dhost</a>,<span class="stringliteral">""</span>);
00037 strcpy(<a class="code" href="classuserrec.html#o3">fullname</a>,<span class="stringliteral">""</span>);
00038 strcpy(<a class="code" href="classuserrec.html#o4">modes</a>,<span class="stringliteral">""</span>);
00039 strcpy(<a class="code" href="classconnection.html#o3">inbuf</a>,<span class="stringliteral">""</span>);
00040 strcpy(<a class="code" href="classuserrec.html#o6">server</a>,<span class="stringliteral">""</span>);
00041 strcpy(<a class="code" href="classuserrec.html#o7">awaymsg</a>,<span class="stringliteral">""</span>);
00042 strcpy(<a class="code" href="classuserrec.html#o11">oper</a>,<span class="stringliteral">""</span>);
00043 <a class="code" href="classuserrec.html#o18">reset_due</a> = <a class="code" href="channels_8cpp.html#a37">TIME</a>;
00044 <a class="code" href="classuserrec.html#o17">lines_in</a> = 0;
00045 <a class="code" href="classconnection.html#o0">fd</a> = <a class="code" href="classconnection.html#o12">lastping</a> = <a class="code" href="classconnection.html#o13">signon</a> = <a class="code" href="classconnection.html#o14">idle_lastmsg</a> = <a class="code" href="classconnection.html#o15">nping</a> = <a class="code" href="classconnection.html#o10">registered</a> = 0;
00046 <a class="code" href="classuserrec.html#o9">flood</a> = <a class="code" href="classconnection.html#o9">port</a> = <a class="code" href="classconnection.html#o4">bytes_in</a> = <a class="code" href="classconnection.html#o5">bytes_out</a> = <a class="code" href="classconnection.html#o6">cmds_in</a> = <a class="code" href="classconnection.html#o7">cmds_out</a> = 0;
00047 <a class="code" href="classconnection.html#o8">haspassed</a> = <span class="keyword">false</span>;
00048 <a class="code" href="classuserrec.html#o12">dns_done</a> = <span class="keyword">false</span>;
00049 <a class="code" href="classuserrec.html#o15">recvq</a> = <span class="stringliteral">""</span>;
00050 <a class="code" href="classuserrec.html#o16">sendq</a> = <span class="stringliteral">""</span>;
00051 strcpy(<a class="code" href="classuserrec.html#o8">result</a>,<span class="stringliteral">""</span>);
00052 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < MAXCHANS; i++)
00053 {
00054 this-><a class="code" href="classuserrec.html#o5">chans</a>[i].<a class="code" href="classucrec.html#o1">channel</a> = NULL;
00055 this-><a class="code" href="classuserrec.html#o5">chans</a>[i].<a class="code" href="classucrec.html#o0">uc_modes</a> = 0;
00056 }
00057 <a class="code" href="classuserrec.html#r0">invites</a>.clear();
00058 }
00059
00060
00061
<a name="l00062"></a><a class="code" href="classuserrec.html#a2">00062</a> <span class="keywordtype">char</span>* <a class="code" href="classuserrec.html#a2">userrec::GetFullHost</a>()
00063 {
00064 snprintf(<a class="code" href="classuserrec.html#o8">result</a>,MAXBUF,<span class="stringliteral">"%s!%s@%s"</span>,<a class="code" href="classuserrec.html#o0">nick</a>,<a class="code" href="classuserrec.html#o1">ident</a>,<a class="code" href="classuserrec.html#o2">dhost</a>);
00065 <span class="keywordflow">return</span> <a class="code" href="classuserrec.html#o8">result</a>;
00066 }
00067
00068
<a name="l00069"></a><a class="code" href="classuserrec.html#a3">00069</a> <span class="keywordtype">char</span>* <a class="code" href="classuserrec.html#a3">userrec::GetFullRealHost</a>()
00070 {
00071 snprintf(<a class="code" href="classuserrec.html#o8">result</a>,MAXBUF,<span class="stringliteral">"%s!%s@%s"</span>,<a class="code" href="classuserrec.html#o0">nick</a>,<a class="code" href="classuserrec.html#o1">ident</a>,<a class="code" href="classconnection.html#o1">host</a>);
00072 <span class="keywordflow">return</span> <a class="code" href="classuserrec.html#o8">result</a>;
00073 }
00074
<a name="l00075"></a><a class="code" href="classuserrec.html#a4">00075</a> <span class="keywordtype">bool</span> <a class="code" href="classuserrec.html#a4">userrec::IsInvited</a>(<span class="keywordtype">char</span>* channel)
00076 {
00077 <span class="keywordflow">for</span> (InvitedList::iterator i = <a class="code" href="classuserrec.html#r0">invites</a>.begin(); i != <a class="code" href="classuserrec.html#r0">invites</a>.end(); i++)
00078 {
00079 <span class="keywordflow">if</span> (i->channel) {
00080 <span class="keywordflow">if</span> (!strcasecmp(i->channel,channel))
00081 {
00082 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00083 }
00084 }
00085 }
00086 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00087 }
00088
<a name="l00089"></a><a class="code" href="classuserrec.html#a5">00089</a> <span class="keywordtype">void</span> <a class="code" href="classuserrec.html#a5">userrec::InviteTo</a>(<span class="keywordtype">char</span>* channel)
00090 {
00091 <a class="code" href="classInvited.html">Invited</a> i;
00092 strlcpy(i.<a class="code" href="classInvited.html#o0">channel</a>,channel,CHANMAX);
00093 <a class="code" href="classuserrec.html#r0">invites</a>.push_back(i);
00094 }
00095
<a name="l00096"></a><a class="code" href="classuserrec.html#a6">00096</a> <span class="keywordtype">void</span> <a class="code" href="classuserrec.html#a6">userrec::RemoveInvite</a>(<span class="keywordtype">char</span>* channel)
00097 {
00098 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Removing invites"</span>);
00099 <span class="keywordflow">if</span> (channel)
00100 {
00101 <span class="keywordflow">if</span> (<a class="code" href="classuserrec.html#r0">invites</a>.size())
00102 {
00103 <span class="keywordflow">for</span> (InvitedList::iterator i = <a class="code" href="classuserrec.html#r0">invites</a>.begin(); i != <a class="code" href="classuserrec.html#r0">invites</a>.end(); i++)
00104 {
00105 <span class="keywordflow">if</span> (i->channel)
00106 {
00107 <span class="keywordflow">if</span> (!strcasecmp(i->channel,channel))
00108 {
00109 <a class="code" href="classuserrec.html#r0">invites</a>.erase(i);
00110 <span class="keywordflow">return</span>;
00111 }
00112 }
00113 }
00114 }
00115 }
00116 }
00117
<a name="l00118"></a><a class="code" href="classuserrec.html#a7">00118</a> <span class="keywordtype">bool</span> <a class="code" href="classuserrec.html#a7">userrec::HasPermission</a>(<span class="keywordtype">char</span>* command)
00119 {
00120 <span class="keywordtype">char</span> TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
00121 <span class="keywordtype">char</span>* mycmd;
00122 <span class="keywordtype">char</span>* savept;
00123 <span class="keywordtype">char</span>* savept2;
00124
00125 <span class="comment">// are they even an oper at all?</span>
00126 <span class="keywordflow">if</span> (strchr(this->modes,<span class="charliteral">'o'</span>))
00127 {
00128 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** HasPermission: %s is an oper"</span>,this->nick);
00129 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j =0; j < ConfValueEnum(<span class="stringliteral">"type"</span>,&<a class="code" href="channels_8cpp.html#a34">config_f</a>); j++)
00130 {
00131 ConfValue(<span class="stringliteral">"type"</span>,<span class="stringliteral">"name"</span>,j,TypeName,&<a class="code" href="channels_8cpp.html#a34">config_f</a>);
00132 <span class="keywordflow">if</span> (!strcmp(TypeName,this->oper))
00133 {
00134 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** HasPermission: %s is an oper of type '%s'"</span>,this->nick,this->oper);
00135 ConfValue(<span class="stringliteral">"type"</span>,<span class="stringliteral">"classes"</span>,j,Classes,&<a class="code" href="channels_8cpp.html#a34">config_f</a>);
00136 <span class="keywordtype">char</span>* myclass = strtok_r(Classes,<span class="stringliteral">" "</span>,&savept);
00137 <span class="keywordflow">while</span> (myclass)
00138 {
00139 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** HasPermission: checking classtype '%s'"</span>,myclass);
00140 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k =0; k < ConfValueEnum(<span class="stringliteral">"class"</span>,&<a class="code" href="channels_8cpp.html#a34">config_f</a>); k++)
00141 {
00142 ConfValue(<span class="stringliteral">"class"</span>,<span class="stringliteral">"name"</span>,k,ClassName,&<a class="code" href="channels_8cpp.html#a34">config_f</a>);
00143 <span class="keywordflow">if</span> (!strcmp(ClassName,myclass))
00144 {
00145 ConfValue(<span class="stringliteral">"class"</span>,<span class="stringliteral">"commands"</span>,k,CommandList,&<a class="code" href="channels_8cpp.html#a34">config_f</a>);
00146 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** HasPermission: found class named %s with commands: '%s'"</span>,ClassName,CommandList);
00147
00148
00149 mycmd = strtok_r(CommandList,<span class="stringliteral">" "</span>,&savept2);
00150 <span class="keywordflow">while</span> (mycmd)
00151 {
00152 <span class="keywordflow">if</span> (!strcasecmp(mycmd,command))
00153 {
00154 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** Command %s found, returning true"</span>,command);
00155 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00156 }
00157 mycmd = strtok_r(NULL,<span class="stringliteral">" "</span>,&savept2);
00158 }
00159 }
00160 }
00161 myclass = strtok_r(NULL,<span class="stringliteral">" "</span>,&savept);
00162 }
00163 }
00164 }
00165 }
00166 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00167 }
00168
00169
<a name="l00170"></a><a class="code" href="classuserrec.html#a8">00170</a> <span class="keywordtype">bool</span> <a class="code" href="classuserrec.html#a8">userrec::AddBuffer</a>(std::string a)
00171 {
00172 std::string b = <span class="stringliteral">""</span>;
00173 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < a.length(); i++)
00174 <span class="keywordflow">if</span> ((a[i] != <span class="charliteral">'\r'</span>) && (a[i] != <span class="charliteral">'\0'</span>) && (a[i] != 7))
00175 b = b + a[i];
00176 std::stringstream stream(<a class="code" href="classuserrec.html#o15">recvq</a>);
00177 stream << b;
00178 <a class="code" href="classuserrec.html#o15">recvq</a> = stream.str();
00179 <span class="keywordtype">int</span> i = 0;
00180 <span class="comment">// count the size of the first line in the buffer.</span>
00181 <span class="keywordflow">while</span> (i < <a class="code" href="classuserrec.html#o15">recvq</a>.length())
00182 {
00183 <span class="keywordflow">if</span> (<a class="code" href="classuserrec.html#o15">recvq</a>[i++] == <span class="charliteral">'\n'</span>)
00184 <span class="keywordflow">break</span>;
00185 }
00186 <span class="keywordflow">if</span> (<a class="code" href="classuserrec.html#o15">recvq</a>.length() > this-><a class="code" href="classuserrec.html#o22">recvqmax</a>)
00187 {
00188 this-><a class="code" href="classuserrec.html#a12">SetWriteError</a>(<span class="stringliteral">"RecvQ exceeded"</span>);
00189 WriteOpers(<span class="stringliteral">"*** User %s RecvQ of %d exceeds connect class maximum of %d"</span>,this->nick,<a class="code" href="classuserrec.html#o15">recvq</a>.length(),this-><a class="code" href="classuserrec.html#o22">recvqmax</a>);
00190 }
00191 <span class="comment">// return false if we've had more than 600 characters WITHOUT</span>
00192 <span class="comment">// a carriage return (this is BAD, drop the socket)</span>
00193 <span class="keywordflow">return</span> (i < 600);
00194 }
00195
<a name="l00196"></a><a class="code" href="classuserrec.html#a9">00196</a> <span class="keywordtype">bool</span> <a class="code" href="classuserrec.html#a9">userrec::BufferIsReady</a>()
00197 {
00198 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classuserrec.html#o15">recvq</a>.length(); i++)
00199 <span class="keywordflow">if</span> (<a class="code" href="classuserrec.html#o15">recvq</a>[i] == <span class="charliteral">'\n'</span>)
00200 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00201 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00202 }
00203
<a name="l00204"></a><a class="code" href="classuserrec.html#a10">00204</a> <span class="keywordtype">void</span> <a class="code" href="classuserrec.html#a10">userrec::ClearBuffer</a>()
00205 {
00206 <a class="code" href="classuserrec.html#o15">recvq</a> = <span class="stringliteral">""</span>;
00207 }
00208
<a name="l00209"></a><a class="code" href="classuserrec.html#a11">00209</a> std::string <a class="code" href="classuserrec.html#a11">userrec::GetBuffer</a>()
00210 {
00211 <span class="keywordflow">if</span> (<a class="code" href="classuserrec.html#o15">recvq</a> == <span class="stringliteral">""</span>)
00212 <span class="keywordflow">return</span> <span class="stringliteral">""</span>;
00213 <span class="keywordtype">char</span>* line = (<span class="keywordtype">char</span>*)<a class="code" href="classuserrec.html#o15">recvq</a>.c_str();
00214 std::string ret = <span class="stringliteral">""</span>;
00215 <span class="keywordflow">while</span> ((*line != <span class="charliteral">'\n'</span>) && (strlen(line)))
00216 {
00217 ret = ret + *line;
00218 line++;
00219 }
00220 <span class="keywordflow">if</span> ((*line == <span class="charliteral">'\n'</span>) || (*line == <span class="charliteral">'\r'</span>))
00221 line++;
00222 <a class="code" href="classuserrec.html#o15">recvq</a> = line;
00223 <span class="keywordflow">return</span> ret;
00224 }
00225
<a name="l00226"></a><a class="code" href="classuserrec.html#a14">00226</a> <span class="keywordtype">void</span> <a class="code" href="classuserrec.html#a14">userrec::AddWriteBuf</a>(std::string data)
00227 {
00228 <span class="keywordflow">if</span> (this-><a class="code" href="classuserrec.html#a13">GetWriteError</a>() != <span class="stringliteral">""</span>)
00229 <span class="keywordflow">return</span>;
00230 <span class="keywordflow">if</span> (<a class="code" href="classuserrec.html#o16">sendq</a>.length() + data.length() > this-><a class="code" href="classuserrec.html#o21">sendqmax</a>)
00231 {
00232 WriteOpers(<span class="stringliteral">"*** User %s SendQ of %d exceeds connect class maximum of %d"</span>,this->nick,<a class="code" href="classuserrec.html#o16">sendq</a>.length() + data.length(),this-><a class="code" href="classuserrec.html#o21">sendqmax</a>);
00233 this-><a class="code" href="classuserrec.html#a12">SetWriteError</a>(<span class="stringliteral">"SendQ exceeded"</span>);
00234 <span class="keywordflow">return</span>;
00235 }
00236 std::stringstream stream;
00237 stream << <a class="code" href="classuserrec.html#o16">sendq</a> << data;
00238 <a class="code" href="classuserrec.html#o16">sendq</a> = stream.str();
00239 }
00240
00241 <span class="comment">// send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)</span>
<a name="l00242"></a><a class="code" href="classuserrec.html#a15">00242</a> <span class="keywordtype">void</span> <a class="code" href="classuserrec.html#a15">userrec::FlushWriteBuf</a>()
00243 {
00244 <span class="keywordflow">if</span> (<a class="code" href="classuserrec.html#o16">sendq</a>.length())
00245 {
00246 <span class="keywordtype">char</span>* tb = (<span class="keywordtype">char</span>*)this-><a class="code" href="classuserrec.html#o16">sendq</a>.c_str();
00247 <span class="keywordtype">int</span> n_sent = write(this->fd,tb,this->sendq.length());
00248 <span class="keywordflow">if</span> (n_sent == -1)
00249 {
00250 this-><a class="code" href="classuserrec.html#a12">SetWriteError</a>(strerror(errno));
00251 }
00252 <span class="keywordflow">else</span>
00253 {
00254 <span class="comment">// advance the queue</span>
00255 tb += n_sent;
00256 this-><a class="code" href="classuserrec.html#o16">sendq</a> = tb;
00257 <span class="comment">// update the user's stats counters</span>
00258 this-><a class="code" href="classconnection.html#o5">bytes_out</a> += n_sent;
00259 this-><a class="code" href="classconnection.html#o7">cmds_out</a>++;
00260 }
00261 }
00262 }
00263
<a name="l00264"></a><a class="code" href="classuserrec.html#a12">00264</a> <span class="keywordtype">void</span> <a class="code" href="classuserrec.html#a12">userrec::SetWriteError</a>(std::string error)
00265 {
00266 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Setting error string for %s to '%s'"</span>,this->nick,error.c_str());
00267 <span class="comment">// don't try to set the error twice, its already set take the first string.</span>
00268 <span class="keywordflow">if</span> (this-><a class="code" href="classuserrec.html#o20">WriteError</a> == <span class="stringliteral">""</span>)
00269 this-><a class="code" href="classuserrec.html#o20">WriteError</a> = error;
00270 }
00271
<a name="l00272"></a><a class="code" href="classuserrec.html#a13">00272</a> std::string <a class="code" href="classuserrec.html#a13">userrec::GetWriteError</a>()
00273 {
00274 <span class="keywordflow">return</span> this-><a class="code" href="classuserrec.html#o20">WriteError</a>;
00275 }
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu May 12 02:25:13 2005 for InspIRCd by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 >
</a>1.3.3 </small></address>
</body>
</html>
|