diff options
author | Adam <Adam@anope.org> | 2012-09-01 18:54:51 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-09-01 18:54:51 -0400 |
commit | e3d5140dcc936ff411c438b7e3997104cb5f085a (patch) | |
tree | 49d7ee0b3e531a1c81e35fb10f25e6340fa781ba /src | |
parent | f81d0113a21187d68c5fa0f1262e5514465b1953 (diff) |
Added a web panel module + a default template
Diffstat (limited to 'src')
-rw-r--r-- | src/access.cpp | 11 | ||||
-rw-r--r-- | src/bots.cpp | 1 | ||||
-rw-r--r-- | src/command.cpp | 7 | ||||
-rw-r--r-- | src/logger.cpp | 6 | ||||
-rw-r--r-- | src/misc.cpp | 19 | ||||
-rw-r--r-- | src/socket_clients.cpp | 2 | ||||
-rw-r--r-- | src/socket_transport.cpp | 40 |
7 files changed, 59 insertions, 27 deletions
diff --git a/src/access.cpp b/src/access.cpp index 40e53a305..6ff842fd8 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -73,10 +73,21 @@ void PrivilegeManager::ClearPrivileges() AccessProvider::AccessProvider(Module *o, const Anope::string &n) : Service(o, "AccessProvider", n) { + providers.push_back(this); } AccessProvider::~AccessProvider() { + std::list<AccessProvider *>::iterator it = std::find(providers.begin(), providers.end(), this); + if (it != providers.end()) + providers.erase(it); +} + +std::list<AccessProvider *> AccessProvider::providers; + +const std::list<AccessProvider *>& AccessProvider::GetProviders() +{ + return providers; } ChanAccess::ChanAccess(AccessProvider *p) : provider(p) diff --git a/src/bots.cpp b/src/bots.cpp index 85d6e0700..53f9b78c1 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -239,7 +239,6 @@ void BotInfo::OnMessage(User *u, const Anope::string &message) return; CommandSource source(u->nick, u, u->Account(), u); - source.c = NULL; source.owner = this; source.service = this; diff --git a/src/command.cpp b/src/command.cpp index ae01ecda4..21901bd34 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -16,7 +16,8 @@ #include "access.h" #include "regchannel.h" -CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r) : nick(n), u(user), nc(core), reply(r) +CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r) : nick(n), u(user), nc(core), reply(r), + c(NULL), owner(NULL), service(NULL) { } @@ -90,7 +91,7 @@ void CommandSource::Reply(const char *message, ...) va_list args; char buf[4096]; // Messages can be really big. - const char *translated_message = translate(this->u, message); + const char *translated_message = translate(this->nc, message); va_start(args, message); vsnprintf(buf, sizeof(buf), translated_message, args); @@ -102,7 +103,7 @@ void CommandSource::Reply(const char *message, ...) void CommandSource::Reply(const Anope::string &message) { - const char *translated_message = translate(this->u, message.c_str()); + const char *translated_message = translate(this->nc, message.c_str()); sepstream sep(translated_message, '\n'); Anope::string tok; diff --git a/src/logger.cpp b/src/logger.cpp index d18b0731e..0624509d2 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -83,7 +83,7 @@ Log::Log(LogType type, const Anope::string &category, const BotInfo *b) : bi(b), this->Sources.push_back(bi->nick); } -Log::Log(LogType type, const CommandSource &source, Command *_c, const ChannelInfo *_ci) : u(source.GetUser()), nc(source.nc), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type) +Log::Log(LogType type, const CommandSource &source, Command *_c, const ChannelInfo *_ci) : nick(source.GetNick()), u(source.GetUser()), nc(source.nc), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type) { if (!c) throw CoreException("Invalid pointers passed to Log::Log"); @@ -210,7 +210,7 @@ Anope::string Log::BuildPrefix() const } case LOG_COMMAND: { - if (!this->c || !(this->u || this->nc)) + if (!this->c) break; buffer += "COMMAND: "; size_t sl = this->c->name.find('/'); @@ -219,6 +219,8 @@ Anope::string Log::BuildPrefix() const buffer += this->u->GetMask() + " used " + cname + " "; else if (this->nc) buffer += this->nc->display + " used " + cname + " "; + else + buffer += this->nick + " used " + cname + " "; if (this->ci) buffer += "on " + this->ci->name + " "; break; diff --git a/src/misc.cpp b/src/misc.cpp index 41f1370a1..ee091c249 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -758,9 +758,9 @@ void Anope::Unhex(const Anope::string &src, Anope::string &dest) { size_t len = src.length(); Anope::string rv; - for (size_t i = 0; i < len; i += 2) + for (size_t i = 0; i + 1 < len; i += 2) { - char h = src[i], l = src[i + 1]; + char h = std::tolower(src[i]), l = std::tolower(src[i + 1]); unsigned char byte = (h >= 'a' ? h - 'a' + 10 : h - '0') << 4; byte += (l >= 'a' ? l - 'a' + 10 : l - '0'); rv += byte; @@ -768,17 +768,12 @@ void Anope::Unhex(const Anope::string &src, Anope::string &dest) dest = rv; } -void Anope::Unhex(const Anope::string &src, char *dest) +void Anope::Unhex(const Anope::string &src, char *dest, size_t sz) { - size_t len = src.length(), destpos = 0; - for (size_t i = 0; i < len; i += 2) - { - char h = src[i], l = src[i + 1]; - unsigned char byte = (h >= 'a' ? h - 'a' + 10 : h - '0') << 4; - byte += (l >= 'a' ? l - 'a' + 10 : l - '0'); - dest[destpos++] = byte; - } - dest[destpos] = 0; + Anope::string d; + Anope::Unhex(src, d); + + strncpy(dest, d.c_str(), sz); } int Anope::LastErrorCode() diff --git a/src/socket_clients.cpp b/src/socket_clients.cpp index 847981510..4d3a1e3ee 100644 --- a/src/socket_clients.cpp +++ b/src/socket_clients.cpp @@ -60,7 +60,7 @@ void ConnectionSocket::OnError(const Anope::string &) { } -ClientSocket::ClientSocket(ListenSocket *ls, const sockaddrs &addr) : Socket(), LS(ls), clientaddr(addr) +ClientSocket::ClientSocket(ListenSocket *ls, const sockaddrs &addr) : LS(ls), clientaddr(addr) { } diff --git a/src/socket_transport.cpp b/src/socket_transport.cpp index b524c6a24..30af95226 100644 --- a/src/socket_transport.cpp +++ b/src/socket_transport.cpp @@ -56,7 +56,7 @@ bool BufferedSocket::ProcessRead() while (stream.GetToken(tbuf)) { tbuf.trim(); - if (!tbuf.empty() && !Read(tbuf)) + if (!Read(tbuf)) return false; } @@ -80,6 +80,12 @@ bool BufferedSocket::Read(const Anope::string &buf) return false; } +void BufferedSocket::Write(const char *buffer, size_t l) +{ + this->WriteBuffer += buffer + Anope::string("\r\n"); + SocketEngine::MarkWritable(this); +} + void BufferedSocket::Write(const char *message, ...) { va_list vi; @@ -89,17 +95,15 @@ void BufferedSocket::Write(const char *message, ...) return; va_start(vi, message); - vsnprintf(tbuffer, sizeof(tbuffer), message, vi); + int len = vsnprintf(tbuffer, sizeof(tbuffer), message, vi); va_end(vi); - Anope::string sbuf = tbuffer; - Write(sbuf); + this->Write(tbuffer, std::min(len, static_cast<int>(sizeof(tbuffer)))); } void BufferedSocket::Write(const Anope::string &message) { - this->WriteBuffer += message + "\r\n"; - SocketEngine::MarkWritable(this); + this->Write(message.c_str(), message.length()); } int BufferedSocket::ReadBufferLen() const @@ -115,14 +119,14 @@ int BufferedSocket::WriteBufferLen() const BinarySocket::DataBlock::DataBlock(const char *b, size_t l) { - this->buf = new char[l]; + this->orig = this->buf = new char[l]; memcpy(this->buf, b, l); this->len = l; } BinarySocket::DataBlock::~DataBlock() { - delete [] this->buf; + delete [] this->orig; } BinarySocket::BinarySocket() @@ -180,6 +184,26 @@ void BinarySocket::Write(const char *buffer, size_t l) SocketEngine::MarkWritable(this); } +void BinarySocket::Write(const char *message, ...) +{ + va_list vi; + char tbuffer[BUFSIZE]; + + if (!message) + return; + + va_start(vi, message); + int len = vsnprintf(tbuffer, sizeof(tbuffer), message, vi); + va_end(vi); + + this->Write(tbuffer, std::min(len, static_cast<int>(sizeof(tbuffer)))); +} + +void BinarySocket::Write(const Anope::string &message) +{ + this->Write(message.c_str(), message.length()); +} + bool BinarySocket::Read(const char *buffer, size_t l) { return true; |