Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

userrec Class Reference

Holds all information about a user This class stores all information about a user connected to the irc server. More...

#include <users.h>

Inheritance diagram for userrec:

Inheritance graph
[legend]
Collaboration diagram for userrec:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 userrec ()
virtual char * GetFullHost ()
 Returns the full displayed host of the user This member function returns the hostname of the user as seen by other users on the server, in nick!identhost form.
virtual char * GetFullRealHost ()
 Returns the full real host of the user This member function returns the hostname of the user as seen by other users on the server, in nick!identhost form.
virtual bool IsInvited (char *channel)
 Returns true if a user is invited to a channel.
virtual void InviteTo (char *channel)
 Adds a channel to a users invite list (invites them to a channel).
virtual void RemoveInvite (char *channel)
 Removes a channel from a users invite list.
bool HasPermission (char *command)
 Returns true or false for if a user can execute a privilaged oper command.
int ReadData (void *buffer, size_t size)
 Calls read() to read some data for this user using their fd.
bool AddBuffer (std::string a)
 This method adds data to the buffer of the user.
bool BufferIsReady ()
 This method returns true if the buffer contains at least one carriage return character (e.g.
void ClearBuffer ()
 This function clears the entire buffer by setting it to an empty string.
std::string GetBuffer ()
 This method returns the first available string at the tail end of the buffer and advances the tail end of the buffer past the string.
void SetWriteError (std::string error)
 Sets the write error for a connection.
std::string GetWriteError ()
 Returns the write error which last occured on this connection or an empty string if none occured.
void AddWriteBuf (std::string data)
 Adds to the user's write buffer.
void FlushWriteBuf ()
 Flushes as much of the user's buffer to the file descriptor as possible.
InvitedListGetInviteList ()
 Returns the list of channels this user has been invited to but has not yet joined.
void CloseSocket ()
 Shuts down and closes the user's socket.
virtual ~userrec ()

Public Attributes

char nick [NICKMAX]
 The users nickname.
char ident [IDENTMAX+2]
 The users ident reply.
char dhost [160]
 The host displayed to non-opers (used for cloaking etc).
char fullname [MAXGECOS+1]
 The users full name.
char modes [54]
 The user's mode string.
ucrec chans [MAXCHANS]
char * server
 The server the user is connected to.
char awaymsg [MAXAWAY+1]
 The user's away message.
int flood
 Number of lines the user can place into the buffer (up to the global NetBufferSize bytes) before they are disconnected for excess flood.
unsigned int timeout
 Number of seconds this user is given to send USER/NICK If they do not send their details in this time limit they will be disconnected.
char oper [NICKMAX]
 The oper type they logged in as, if they are an oper.
bool dns_done
 True when DNS lookups are completed.
unsigned int pingmax
 Number of seconds between PINGs for this user (set from <connect:allow> tag.
char password [MAXBUF]
 Password specified by the user when they registered.
std::string recvq
 User's receive queue.
std::string sendq
 User's send queue.
int lines_in
 Flood counters.
time_t reset_due
long threshold
std::string WriteError
long sendqmax
 Maximum size this user's sendq can become.
long recvqmax
 Maximum size this user's recvq can become.

Private Attributes

InvitedList invites
 A list of channels the user has a pending invite to.

Detailed Description

Holds all information about a user This class stores all information about a user connected to the irc server.

Everything about a connection is stored here primarily, from the user's socket ID (file descriptor) through to the user's nickname and hostname. Use the Find method of the server class to locate a specific user by nickname.

Definition at line 111 of file users.h.


Constructor & Destructor Documentation

userrec::userrec  ) 
 

Definition at line 38 of file users.cpp.

References awaymsg, connection::bytes_in, connection::bytes_out, ucrec::channel, chans, connection::cmds_in, connection::cmds_out, dhost, dns_done, connection::fd, flood, fullname, connection::haspassed, connection::host, ident, connection::idle_lastmsg, invites, connection::ip, connection::lastping, lines_in, modes, nick, connection::nping, oper, connection::port, recvq, connection::registered, reset_due, sendq, server, ServerName, connection::signon, TIME, timeout, and ucrec::uc_modes.

00039 {
00040         // the PROPER way to do it, AVOID bzero at *ALL* costs
00041         strcpy(nick,"");
00042         strcpy(ip,"127.0.0.1");
00043         timeout = 0;
00044         strcpy(ident,"");
00045         strcpy(host,"");
00046         strcpy(dhost,"");
00047         strcpy(fullname,"");
00048         strcpy(modes,"");
00049         server = (char*)FindServerNamePtr(ServerName);
00050         strcpy(awaymsg,"");
00051         strcpy(oper,"");
00052         reset_due = TIME;
00053         lines_in = 0;
00054         fd = lastping = signon = idle_lastmsg = nping = registered = 0;
00055         flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
00056         haspassed = false;
00057         dns_done = false;
00058         recvq = "";
00059         sendq = "";
00060         for (int i = 0; i < MAXCHANS; i++)
00061         {
00062                 this->chans[i].channel = NULL;
00063                 this->chans[i].uc_modes = 0;
00064         }
00065         invites.clear();
00066 }

userrec::~userrec  )  [virtual]
 

Definition at line 68 of file users.cpp.

00069 {
00070 }


Member Function Documentation

bool userrec::AddBuffer std::string  a  ) 
 

This method adds data to the buffer of the user.

The buffer can grow to any size within limits of the available memory, managed by the size of a std::string, however if any individual line in the buffer grows over 600 bytes in length (which is 88 chars over the RFC-specified limit per line) then the method will return false and the text will not be inserted.

Definition at line 205 of file users.cpp.

References recvq, recvqmax, and SetWriteError().

00206 {
00207         std::string b = "";
00208         for (unsigned int i = 0; i < a.length(); i++)
00209                 if ((a[i] != '\r') && (a[i] != '\0') && (a[i] != 7))
00210                         b = b + a[i];
00211         std::stringstream stream(recvq);
00212         stream << b;
00213         recvq = stream.str();
00214         unsigned int i = 0;
00215         // count the size of the first line in the buffer.
00216         while (i < recvq.length())
00217         {
00218                 if (recvq[i++] == '\n')
00219                         break;
00220         }
00221         if (recvq.length() > (unsigned)this->recvqmax)
00222         {
00223                 this->SetWriteError("RecvQ exceeded");
00224                 WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax);
00225         }
00226         // return false if we've had more than 600 characters WITHOUT
00227         // a carriage return (this is BAD, drop the socket)
00228         return (i < 600);
00229 }

void userrec::AddWriteBuf std::string  data  ) 
 

Adds to the user's write buffer.

You may add any amount of text up to this users sendq value, if you exceed the sendq value, SetWriteError() will be called to set the users error string to "SendQ exceeded", and further buffer adds will be dropped.

Definition at line 261 of file users.cpp.

References sendq, sendqmax, and SetWriteError().

00262 {
00263         if (this->GetWriteError() != "")
00264                 return;
00265         if (sendq.length() + data.length() > (unsigned)this->sendqmax)
00266         {
00267                 WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax);
00268                 this->SetWriteError("SendQ exceeded");
00269                 return;
00270         }
00271         std::stringstream stream;
00272         stream << sendq << data;
00273         sendq = stream.str();
00274 }

bool userrec::BufferIsReady  ) 
 

This method returns true if the buffer contains at least one carriage return character (e.g.

one complete line may be read)

Definition at line 231 of file users.cpp.

References recvq.

00232 {
00233         for (unsigned int i = 0; i < recvq.length(); i++)
00234                 if (recvq[i] == '\n')
00235                         return true;
00236         return false;
00237 }

void userrec::ClearBuffer  ) 
 

This function clears the entire buffer by setting it to an empty string.

Definition at line 239 of file users.cpp.

References recvq.

Referenced by Server::PseudoToUser(), and Server::UserToPseudo().

00240 {
00241         recvq = "";
00242 }

void userrec::CloseSocket  ) 
 

Shuts down and closes the user's socket.

Definition at line 72 of file users.cpp.

00073 {
00074         shutdown(this->fd,2);
00075         close(this->fd);
00076 }

void userrec::FlushWriteBuf  ) 
 

Flushes as much of the user's buffer to the file descriptor as possible.

This function may not always flush the entire buffer, rather instead as much of it as it possibly can. If the send() call fails to send the entire buffer, the buffer position is advanced forwards and the rest of the data sent at the next call to this method.

Definition at line 277 of file users.cpp.

References connection::bytes_out, connection::cmds_out, sendq, and SetWriteError().

00278 {
00279         if (sendq.length())
00280         {
00281                 char* tb = (char*)this->sendq.c_str();
00282                 int n_sent = write(this->fd,tb,this->sendq.length());
00283                 if (n_sent == -1)
00284                 {
00285                         this->SetWriteError(strerror(errno));
00286                 }
00287                 else
00288                 {
00289                         // advance the queue
00290                         tb += n_sent;
00291                         this->sendq = tb;
00292                         // update the user's stats counters
00293                         this->bytes_out += n_sent;
00294                         this->cmds_out++;
00295                 }
00296         }
00297 }

std::string userrec::GetBuffer  ) 
 

This method returns the first available string at the tail end of the buffer and advances the tail end of the buffer past the string.

This means it is a one way operation in a similar way to strtok(), and multiple calls return multiple lines if they are available. The results of this function if there are no lines to be read are unknown, always use BufferIsReady() to check if it is ok to read the buffer before calling GetBuffer().

Definition at line 244 of file users.cpp.

References recvq.

00245 {
00246         if (recvq == "")
00247                 return "";
00248         char* line = (char*)recvq.c_str();
00249         std::string ret = "";
00250         while ((*line != '\n') && (strlen(line)))
00251         {
00252                 ret = ret + *line;
00253                 line++;
00254         }
00255         if ((*line == '\n') || (*line == '\r'))
00256                 line++;
00257         recvq = line;
00258         return ret;
00259 }

char * userrec::GetFullHost  )  [virtual]
 

Returns the full displayed host of the user This member function returns the hostname of the user as seen by other users on the server, in nick!identhost form.

Definition at line 78 of file users.cpp.

References dhost, ident, and nick.

00079 {
00080         static char result[MAXBUF];
00081         snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,dhost);
00082         return result;
00083 }

char * userrec::GetFullRealHost  )  [virtual]
 

Returns the full real host of the user This member function returns the hostname of the user as seen by other users on the server, in nick!identhost form.

If any form of hostname cloaking is in operation, e.g. through a module, then this method will ignore it and return the true hostname.

Definition at line 96 of file users.cpp.

References connection::host, ident, and nick.

00097 {
00098         static char fresult[MAXBUF];
00099         snprintf(fresult,MAXBUF,"%s!%s@%s",nick,ident,host);
00100         return fresult;
00101 }

InvitedList * userrec::GetInviteList  ) 
 

Returns the list of channels this user has been invited to but has not yet joined.

Definition at line 117 of file users.cpp.

References invites.

00118 {
00119         return &invites;
00120 }

std::string userrec::GetWriteError  ) 
 

Returns the write error which last occured on this connection or an empty string if none occured.

Definition at line 307 of file users.cpp.

References WriteError.

00308 {
00309         return this->WriteError;
00310 }

bool userrec::HasPermission char *  command  ) 
 

Returns true or false for if a user can execute a privilaged oper command.

This is done by looking up their oper type from userrec::oper, then referencing this to their oper classes and checking the commands they can execute.

Definition at line 151 of file users.cpp.

References config_f, and is_uline().

00152 {
00153         char TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
00154         char* mycmd;
00155         char* savept;
00156         char* savept2;
00157         
00158         // users on u-lined servers can completely bypass
00159         // all permissions based checks.
00160         //
00161         // of course, if this is sent to a remote server and this
00162         // server is not ulined there, then that other server
00163         // silently drops the command.
00164         if (is_uline(this->server))
00165                 return true;
00166         
00167         // are they even an oper at all?
00168         if (strchr(this->modes,'o'))
00169         {
00170                 for (int j =0; j < ConfValueEnum("type",&config_f); j++)
00171                 {
00172                         ConfValue("type","name",j,TypeName,&config_f);
00173                         if (!strcmp(TypeName,this->oper))
00174                         {
00175                                 ConfValue("type","classes",j,Classes,&config_f);
00176                                 char* myclass = strtok_r(Classes," ",&savept);
00177                                 while (myclass)
00178                                 {
00179                                         for (int k =0; k < ConfValueEnum("class",&config_f); k++)
00180                                         {
00181                                                 ConfValue("class","name",k,ClassName,&config_f);
00182                                                 if (!strcmp(ClassName,myclass))
00183                                                 {
00184                                                         ConfValue("class","commands",k,CommandList,&config_f);
00185                                                         mycmd = strtok_r(CommandList," ",&savept2);
00186                                                         while (mycmd)
00187                                                         {
00188                                                                 if ((!strcasecmp(mycmd,command)) || (*mycmd == '*'))
00189                                                                 {
00190                                                                         return true;
00191                                                                 }
00192                                                                 mycmd = strtok_r(NULL," ",&savept2);
00193                                                         }
00194                                                 }
00195                                         }
00196                                         myclass = strtok_r(NULL," ",&savept);
00197                                 }
00198                         }
00199                 }
00200         }
00201         return false;
00202 }

void userrec::InviteTo char *  channel  )  [virtual]
 

Adds a channel to a users invite list (invites them to a channel).

Definition at line 122 of file users.cpp.

References Invited::channel, and invites.

00123 {
00124         Invited i;
00125         strlcpy(i.channel,channel,CHANMAX);
00126         invites.push_back(i);
00127 }

bool userrec::IsInvited char *  channel  )  [virtual]
 

Returns true if a user is invited to a channel.

Definition at line 103 of file users.cpp.

References invites.

00104 {
00105         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
00106         {
00107                 if (i->channel) {
00108                         if (!strcasecmp(i->channel,channel))
00109                         {
00110                                 return true;
00111                         }
00112                 }
00113         }
00114         return false;
00115 }

int userrec::ReadData void *  buffer,
size_t  size
 

Calls read() to read some data for this user using their fd.

Definition at line 85 of file users.cpp.

References DEBUG.

00086 {
00087         if (this->fd > -1)
00088         {
00089                 log(DEBUG,"userrec::ReadData on fd %d",this->fd);
00090                 return read(this->fd, buffer, size);
00091         }
00092         else return 0;
00093 }

void userrec::RemoveInvite char *  channel  )  [virtual]
 

Removes a channel from a users invite list.

This member function is called on successfully joining an invite only channel to which the user has previously been invited, to clear the invitation.

Definition at line 129 of file users.cpp.

References DEBUG, and invites.

00130 {
00131         log(DEBUG,"Removing invites");
00132         if (channel)
00133         {
00134                 if (invites.size())
00135                 {
00136                         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
00137                         {
00138                                 if (i->channel)
00139                                 {
00140                                         if (!strcasecmp(i->channel,channel))
00141                                         {
00142                                                 invites.erase(i);
00143                                                 return;
00144                                         }
00145                                 }
00146                         }
00147                 }
00148         }
00149 }

void userrec::SetWriteError std::string  error  ) 
 

Sets the write error for a connection.

This is done because the actual disconnect of a client may occur at an inopportune time such as half way through /LIST output. The WriteErrors of clients are checked at a more ideal time (in the mainloop) and errored clients purged.

Definition at line 299 of file users.cpp.

References DEBUG, and WriteError.

Referenced by AddBuffer(), AddWriteBuf(), and FlushWriteBuf().

00300 {
00301         log(DEBUG,"Setting error string for %s to '%s'",this->nick,error.c_str());
00302         // don't try to set the error twice, its already set take the first string.
00303         if (this->WriteError == "")
00304                 this->WriteError = error;
00305 }


Member Data Documentation

char userrec::awaymsg[MAXAWAY+1]
 

The user's away message.

If this string is empty, the user is not marked as away.

Definition at line 158 of file users.h.

Referenced by userrec().

ucrec userrec::chans[MAXCHANS]
 

Definition at line 149 of file users.h.

Referenced by Server::PseudoToUser(), and userrec().

char userrec::dhost[160]
 

The host displayed to non-opers (used for cloaking etc).

This usually matches the value of userrec::host.

Definition at line 134 of file users.h.

Referenced by GetFullHost(), and userrec().

bool userrec::dns_done
 

True when DNS lookups are completed.

Definition at line 181 of file users.h.

Referenced by userrec().

int userrec::flood
 

Number of lines the user can place into the buffer (up to the global NetBufferSize bytes) before they are disconnected for excess flood.

Definition at line 164 of file users.h.

Referenced by userrec().

char userrec::fullname[MAXGECOS+1]
 

The users full name.

Definition at line 138 of file users.h.

Referenced by userrec().

char userrec::ident[IDENTMAX+2]
 

The users ident reply.

Two characters are added to the user-defined limit to compensate for the tilde etc.

Definition at line 129 of file users.h.

Referenced by GetFullHost(), GetFullRealHost(), Server::PseudoToUser(), userrec(), and Server::UserToPseudo().

InvitedList userrec::invites [private]
 

A list of channels the user has a pending invite to.

Definition at line 117 of file users.h.

Referenced by GetInviteList(), InviteTo(), IsInvited(), RemoveInvite(), and userrec().

int userrec::lines_in
 

Flood counters.

Definition at line 206 of file users.h.

Referenced by userrec().

char userrec::modes[54]
 

The user's mode string.

This may contain any of the following RFC characters: o, w, s, i Your module may define other mode characters as it sees fit. it is limited to length 54, as there can only be a maximum of 52 user modes (26 upper, 26 lower case) a null terminating char, and an optional + character.

Definition at line 147 of file users.h.

Referenced by userrec().

char userrec::nick[NICKMAX]
 

The users nickname.

An invalid nickname indicates an unregistered connection prior to the NICK command.

Definition at line 124 of file users.h.

Referenced by ConfigReader::DumpErrors(), GetFullHost(), GetFullRealHost(), Server::PseudoToUser(), and userrec().

char userrec::oper[NICKMAX]
 

The oper type they logged in as, if they are an oper.

This is used to check permissions in operclasses, so that we can say 'yay' or 'nay' to any commands they issue. The value of this is the value of a valid 'type name=' tag.

Definition at line 177 of file users.h.

Referenced by userrec().

char userrec::password[MAXBUF]
 

Password specified by the user when they registered.

This is stored even if the <connect> block doesnt need a password, so that modules may check it.

Definition at line 191 of file users.h.

unsigned int userrec::pingmax
 

Number of seconds between PINGs for this user (set from <connect:allow> tag.

Definition at line 185 of file users.h.

std::string userrec::recvq
 

User's receive queue.

Lines from the IRCd awaiting processing are stored here. Upgraded april 2005, old system a bit hairy.

Definition at line 197 of file users.h.

Referenced by AddBuffer(), BufferIsReady(), ClearBuffer(), GetBuffer(), and userrec().

long userrec::recvqmax
 

Maximum size this user's recvq can become.

Definition at line 220 of file users.h.

Referenced by AddBuffer().

time_t userrec::reset_due
 

Definition at line 207 of file users.h.

Referenced by userrec().

std::string userrec::sendq
 

User's send queue.

Lines waiting to be sent are stored here until their buffer is flushed.

Definition at line 202 of file users.h.

Referenced by AddWriteBuf(), FlushWriteBuf(), and userrec().

long userrec::sendqmax
 

Maximum size this user's sendq can become.

Definition at line 216 of file users.h.

Referenced by AddWriteBuf().

char* userrec::server
 

The server the user is connected to.

Definition at line 153 of file users.h.

Referenced by userrec().

long userrec::threshold
 

Definition at line 208 of file users.h.

unsigned int userrec::timeout
 

Number of seconds this user is given to send USER/NICK If they do not send their details in this time limit they will be disconnected.

Definition at line 170 of file users.h.

Referenced by userrec().

std::string userrec::WriteError
 

Definition at line 212 of file users.h.

Referenced by GetWriteError(), and SetWriteError().


The documentation for this class was generated from the following files:
Generated on Mon Dec 12 13:31:13 2005 for InspIRCd by  doxygen 1.4.4-20050815