]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Missing referece for pthread_kill
[user/henk/code/inspircd.git] / src / users.cpp
index 0ece63bc9ac7b759ca1dc0571301a50fde3ad6e6..6418274282b8380fcce10e26e3a716d2e3562758 100644 (file)
  * ---------------------------------------------------
  */
 
+using namespace std;
+
 #include "inspircd_config.h" 
 #include "channels.h"
+#include "connection.h"
 #include "users.h"
 #include "inspircd.h"
 #include <stdio.h>
+#include <pthread.h>
+#include <signal.h>
 #include "inspstring.h"
+#include "helperfuncs.h"
 
 extern std::stringstream config_f;
+extern char ServerName[MAXBUF];
 
 extern time_t TIME;
 
@@ -36,8 +43,7 @@ userrec::userrec()
        strcpy(dhost,"");
        strcpy(fullname,"");
        strcpy(modes,"");
-       strcpy(inbuf,"");
-       strcpy(server,"");
+       server = (char*)FindServerNamePtr(ServerName);
        strcpy(awaymsg,"");
        strcpy(oper,"");
        reset_due = TIME;
@@ -47,7 +53,7 @@ userrec::userrec()
        haspassed = false;
        dns_done = false;
        recvq = "";
-       strcpy(result,"");
+       sendq = "";
        for (int i = 0; i < MAXCHANS; i++)
        {
                this->chans[i].channel = NULL;
@@ -56,19 +62,40 @@ userrec::userrec()
        invites.clear();
 }
 
+userrec::~userrec()
+{
+       pthread_kill(this->dnsthread,9);
+}
 
+void userrec::CloseSocket()
+{
+       shutdown(this->fd,2);
+       close(this->fd);
+}
  
 char* userrec::GetFullHost()
 {
+       static char result[MAXBUF];
        snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,dhost);
        return result;
 }
 
+int userrec::ReadData(void* buffer, size_t size)
+{
+       if (this->fd > -1)
+       {
+               log(DEBUG,"userrec::ReadData on fd %d",this->fd);
+               return read(this->fd, buffer, size);
+       }
+       else return 0;
+}
+
 
 char* userrec::GetFullRealHost()
 {
-       snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,host);
-       return result;
+       static char fresult[MAXBUF];
+       snprintf(fresult,MAXBUF,"%s!%s@%s",nick,ident,host);
+       return fresult;
 }
 
 bool userrec::IsInvited(char* channel)
@@ -85,6 +112,11 @@ bool userrec::IsInvited(char* channel)
        return false;
 }
 
+InvitedList* userrec::GetInviteList()
+{
+       return &invites;
+}
+
 void userrec::InviteTo(char* channel)
 {
        Invited i;
@@ -166,20 +198,35 @@ bool userrec::HasPermission(char* command)
 }
 
 
-void userrec::AddBuffer(std::string a)
+bool userrec::AddBuffer(std::string a)
 {
         std::string b = "";
-        for (int i = 0; i < a.length(); i++)
+        for (unsigned int i = 0; i < a.length(); i++)
                 if ((a[i] != '\r') && (a[i] != '\0') && (a[i] != 7))
                         b = b + a[i];
         std::stringstream stream(recvq);
         stream << b;
         recvq = stream.str();
+       unsigned int i = 0;
+       // count the size of the first line in the buffer.
+       while (i < recvq.length())
+       {
+               if (recvq[i++] == '\n')
+                       break;
+       }
+       if (recvq.length() > (unsigned)this->recvqmax)
+       {
+               this->SetWriteError("RecvQ exceeded");
+               WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax);
+       }
+       // return false if we've had more than 600 characters WITHOUT
+       // a carriage return (this is BAD, drop the socket)
+       return (i < 600);
 }
 
 bool userrec::BufferIsReady()
 {
-        for (int i = 0; i < recvq.length(); i++)
+        for (unsigned int i = 0; i < recvq.length(); i++)
                if (recvq[i] == '\n')
                        return true;
         return false;
@@ -192,7 +239,8 @@ void userrec::ClearBuffer()
 
 std::string userrec::GetBuffer()
 {
-       log(DEBUG,"GetBuffer\n%s\n",recvq.c_str());
+       if (recvq == "")
+               return "";
         char* line = (char*)recvq.c_str();
         std::string ret = "";
         while ((*line != '\n') && (strlen(line)))
@@ -206,3 +254,53 @@ std::string userrec::GetBuffer()
         return ret;
 }
 
+void userrec::AddWriteBuf(std::string data)
+{
+       if (this->GetWriteError() != "")
+               return;
+       if (sendq.length() + data.length() > (unsigned)this->sendqmax)
+       {
+               WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax);
+               this->SetWriteError("SendQ exceeded");
+               return;
+       }
+        std::stringstream stream;
+        stream << sendq << data;
+        sendq = stream.str();
+}
+
+// send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
+void userrec::FlushWriteBuf()
+{
+       if (sendq.length())
+       {
+               char* tb = (char*)this->sendq.c_str();
+               int n_sent = write(this->fd,tb,this->sendq.length());
+               if (n_sent == -1)
+               {
+                       this->SetWriteError(strerror(errno));
+               }
+               else
+               {
+                       // advance the queue
+                       tb += n_sent;
+                       this->sendq = tb;
+                       // update the user's stats counters
+                       this->bytes_out += n_sent;
+                       this->cmds_out++;
+               }
+       }
+}
+
+void userrec::SetWriteError(std::string error)
+{
+       log(DEBUG,"Setting error string for %s to '%s'",this->nick,error.c_str());
+       // don't try to set the error twice, its already set take the first string.
+       if (this->WriteError == "")
+               this->WriteError = error;
+}
+
+std::string userrec::GetWriteError()
+{
+       return this->WriteError;
+}