summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-26 13:31:24 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-26 13:31:24 +0000
commit1f56002af538fe6e2ddaecb96add7053245ad3ad (patch)
treed289bb826d2d5cb614132e70e598caead8d5b9db
parent4d4e4359d64e25c2adee14333e9f192d21425c94 (diff)
Fixed dicky buffer (due to cleanup the wrong variable was being used)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1193 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/connection.h9
-rw-r--r--src/commands.cpp8
-rw-r--r--src/connection.cpp51
3 files changed, 39 insertions, 29 deletions
diff --git a/include/connection.h b/include/connection.h
index 304f20cd9..614a3146d 100644
--- a/include/connection.h
+++ b/include/connection.h
@@ -27,6 +27,7 @@
#include <time.h>
#include <vector>
#include <deque>
+#include <sstream>
#ifndef __CONNECTION_H__
#define __CONNECTION_H__
@@ -78,11 +79,13 @@ class ircd_connector : public Extensible
*/
bool SetHostAddress(char* host, int port);
- /** IRCD Buffer for input characters, holds one line
- */
- std::string ircdbuffer;
public:
+
+ /** IRCD Buffer for input characters, holds one line
+ */
+ std::string ircdbuffer;
+
/** When MakeOutboundConnection is called, these public members are
* filled with the details passed to the function, for future
diff --git a/src/commands.cpp b/src/commands.cpp
index 8b024544e..9f3013546 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -3140,8 +3140,6 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
}
}
}
- WriteOpers("\2WARNING!\2 %s sent us an authentication packet but we are not authenticating with this server right noe! Possible intrusion attempt!",tcp_host);
- return;
}
}
else {
@@ -3172,7 +3170,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
char Link_SendPass[1024];
int LinkPort = 0;
- log(DEBUG,"U-token linked server detected.");
+ log(DEBUG,"U-token linked server detected.\n\nservername='%s' password='%s'\n\n",servername,password);
for (int j = 0; j < 32; j++)
@@ -3218,6 +3216,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),tcp_host))
{
char buffer[MAXBUF];
+ log(DEBUG,"Found matching link block");
me[j]->connectors[k].SetDescription(serverdesc);
me[j]->connectors[k].SetServerName(servername);
me[j]->connectors[k].SetState(STATE_SERVICES);
@@ -3235,14 +3234,13 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
}
}
}
- WriteOpers("\2WARNING!\2 %s sent us an authentication packet but we are not authenticating with this server right noe! Possible intrusion attempt!",tcp_host);
- return;
}
}
else {
log(DEBUG,"Server names '%s' and '%s' don't match",Link_ServerName,servername);
}
}
+ log(DEBUG,"No matching link block found");
char buffer[MAXBUF];
sprintf(buffer,"E :Access is denied (no matching link block)");
serv->SendPacket(buffer,tcp_host);
diff --git a/src/connection.cpp b/src/connection.cpp
index cd994ea65..d05a304f6 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -24,6 +24,7 @@
#include <vector>
#include <string>
#include <deque>
+#include <sstream>
#include "inspircd.h"
#include "modules.h"
#include "inspstring.h"
@@ -139,9 +140,14 @@ void ircd_connector::SetServerPort(int p)
void ircd_connector::AddBuffer(std::string a)
{
+ std::string b = "";
for (int i = 0; i < a.length(); i++)
if (a[i] != '\r')
- ircdbuffer = ircdbuffer + a[i];
+ b = b + a[i];
+
+ std::stringstream stream(ircdbuffer);
+ stream << b;
+ ircdbuffer = stream.str();
}
bool ircd_connector::BufferIsComplete()
@@ -154,24 +160,23 @@ bool ircd_connector::BufferIsComplete()
void ircd_connector::ClearBuffer()
{
- while ((ircdbuffer != "") && (ircdbuffer[0] != '\n'))
- {
- ircdbuffer.erase(ircdbuffer.begin());
- }
- if (ircdbuffer != "")
- ircdbuffer.erase(ircdbuffer.begin());
+ ircdbuffer = "";
}
std::string ircd_connector::GetBuffer()
{
- std::string z = "";
- long t = 0;
- while (ircdbuffer[t] != '\n')
- {
- z = z + ircdbuffer[t];
- t++;
- }
- return z;
+ char* line = (char*)ircdbuffer.c_str();
+ char ret[MAXBUF];
+ std::stringstream* stream = new std::stringstream(std::stringstream::in | std::stringstream::out);
+ *stream << ircdbuffer;
+ stream->getline(ret,MAXBUF);
+ while ((*line != '\n') && (strlen(line)))
+ line++;
+ if ((*line == '\n') || (*line == '\r'))
+ line++;
+ ircdbuffer = line;
+ delete stream;
+ return ret;
}
bool ircd_connector::MakeOutboundConnection(char* newhost, int newport)
@@ -406,7 +411,7 @@ bool connection::SendPacket(char *message, const char* sendhost)
{
log(DEBUG,"Main route to %s is down, seeking alternative",host);
// fix: can only route one hop to avoid a loop
- if (strncmp(message,"R ",2))
+ if (!strncmp(message,"R ",2))
{
// this route is down, we must re-route the packet through an available point in the mesh.
for (int k = 0; k < this->connectors.size(); k++)
@@ -460,7 +465,7 @@ bool connection::RecvPacket(std::deque<std::string> &messages, char* recvhost)
{
// returns false if the packet could not be sent (e.g. target host down)
int rcvsize = 0;
- rcvsize = recv(this->connectors[i].GetDescriptor(),data,32,0);
+ rcvsize = recv(this->connectors[i].GetDescriptor(),data,4096,0);
data[rcvsize] = '\0';
if (rcvsize == -1)
{
@@ -472,15 +477,19 @@ bool connection::RecvPacket(std::deque<std::string> &messages, char* recvhost)
this->connectors[i].SetState(STATE_DISCONNECTED);
}
}
+ int pushed = 0;
if (rcvsize > 0)
{
this->connectors[i].AddBuffer(data);
if (this->connectors[i].BufferIsComplete())
{
- messages.push_back(this->connectors[i].GetBuffer().c_str());
- strlcpy(host,this->connectors[i].GetServerName().c_str(),160);
- log(DEBUG,"main: Connection::RecvPacket() got '%s' from %s",this->connectors[i].GetBuffer().c_str(),recvhost);
- this->connectors[i].ClearBuffer();
+ while (this->connectors[i].BufferIsComplete())
+ {
+ std::string text = this->connectors[i].GetBuffer();
+ messages.push_back(text.c_str());
+ strlcpy(recvhost,this->connectors[i].GetServerName().c_str(),160);
+ log(DEBUG,"main: Connection::RecvPacket() %d:%s->%s",pushed++,recvhost,text.c_str());
+ }
return true;
}
}