aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorGravatar Szymon Tomasz Stefanek2008-04-28 01:31:42 +0000
committerGravatar Szymon Tomasz Stefanek2008-04-28 01:31:42 +0000
commit6eff13c1b9d284fad598bc4ad92826db29723926 (patch)
tree7797f07f76f4826010215fad47a31191155dfd04 /src/modules
parentfix compilation error (diff)
downloadKVIrc-6eff13c1b9d284fad598bc4ad92826db29723926.tar.gz
KVIrc-6eff13c1b9d284fad598bc4ad92826db29723926.tar.bz2
KVIrc-6eff13c1b9d284fad598bc4ad92826db29723926.zip
A huge progress in KDE4 port, kvirc and several modules now compile. Linking problems solved. Added an option to pick up a random IP address for round-robin IRC servers. Some code cleanup all around...
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@1608 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/dcc/libkvidcc.cpp2
-rw-r--r--src/modules/dcc/marshal.cpp20
-rw-r--r--src/modules/dcc/requests.cpp55
-rw-r--r--src/modules/dcc/send.cpp8
-rw-r--r--src/modules/options/optw_connection.cpp4
-rw-r--r--src/modules/trayicon/libkvitrayicon.cpp6
-rw-r--r--src/modules/window/libkviwindow.cpp10
7 files changed, 59 insertions, 46 deletions
diff --git a/src/modules/dcc/libkvidcc.cpp b/src/modules/dcc/libkvidcc.cpp
index 1efb2a6ec..7909a53cd 100644
--- a/src/modules/dcc/libkvidcc.cpp
+++ b/src/modules/dcc/libkvidcc.cpp
@@ -1143,7 +1143,7 @@ static bool dcc_kvs_cmd_voice(KviKvsModuleCommandCall * c)
QString szCodec;
pCodec->asString(szCodec);
- if(!kvi_dcc_voice_is_valid_codec(szCodec))
+ if(!kvi_dcc_voice_is_valid_codec(szCodec.toUtf8().data()))
{
c->warning(__tr2qs_ctx("Invalid codec specified, defaulting to 'adpcm'","dcc"));
pre { line-height: 125%; } td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888 } /* Comment */ .highlight .err { color: #A61717; background-color: #E3D2D2 } /* Error */ .highlight .k { color: #080; font-weight: bold } /* Keyword */ .highlight .ch { color: #888 } /* Comment.Hashbang */ .highlight .cm { color: #888 } /* Comment.Multiline */ .highlight .cp { color: #C00; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888 } /* Comment.Single */ .highlight .cs { color: #C00; font-weight: bold; background-color: #FFF0F0 } /* Comment.Special */ .highlight .gd { color: #000; background-color: #FDD } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #A00 } /* Generic.Error */ .highlight .gh { color: #333 } /* Generic.Heading */ .highlight .gi { color: #000; background-color: #DFD } /* Generic.Inserted */ .highlight .go { color: #888 } /* Generic.Output */ .highlight .gp { color: #555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666 } /* Generic.Subheading */ .highlight .gt { color: #A00 } /* Generic.Traceback */ .highlight .kc { color: #080; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #080; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #080; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #080 } /* Keyword.Pseudo */ .highlight .kr { color: #080; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #00D; font-weight: bold } /* Literal.Number */ .highlight .s { color: #D20; background-color: #FFF0F0 } /* Literal.String */ .highlight .na { color: #369 } /* Name.Attribute */ .highlight .nb { color: #038 } /* Name.Builtin */ .highlight .nc { color: #B06; font-weight: bold } /* Name.Class */ .highlight .no { color: #036; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555 } /* Name.Decorator */ .highlight .ne { color: #B06; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #06B; font-weight: bold } /* Name.Function */ .highlight .nl { color: #369; font-style: italic } /* Name.Label */ .highlight .nn { color: #B06; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #369; font-weight: bold } /* Name.Property */ .highlight .nt { color: #B06; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #369 } /* Name.Variable */ .highlight .ow { color: #080 } /* Operator.Word */ .highlight .w { color: #BBB } /* Text.Whitespace */ .highlight .mb { color: #00D; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #00D; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #00D; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #00D; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #00D; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #D20; background-color: #FFF0F0 } /* Literal.String.Affix */ .highlight .sb { color: #D20; background-color: #FFF0F0 } /* Literal.String.Backtick */ .highlight .sc { color: #D20; background-color: #FFF0F0 } /* Literal.String.Char */ .highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */ .highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */ .highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */ .highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */ .highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */ .highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */ .highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * InspIRCd -- Internet Relay Chat Daemon
 *
 *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
 *   Copyright (C) 2009 Uli Schlachter <psychon@znc.in>
 *   Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
 *
 * This file is part of InspIRCd.  InspIRCd is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, version 2.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "inspircd.h"

#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#include <sys/sysctl.h>

/** A specialisation of the SocketEngine class, designed to use BSD kqueue().
 */
namespace
{
	int EngineHandle;
	unsigned int ChangePos = 0;
	/** These are used by kqueue() to hold socket events
	 */
	std::vector<struct kevent> ke_list(16);

	/** Pending changes
	 */
	std::vector<struct kevent> changelist(8);

#ifdef __NetBSD__
	inline intptr_t udata_cast(EventHandler* eh)
	{
		// On NetBSD the last parameter of EV_SET is intptr_t.
		return reinterpret_cast<intptr_t>(eh);
	}
#else
	inline void* udata_cast(EventHandler* eh)
	{
		// On other platforms the last parameter of EV_SET is void*.
		return static_cast<void*>(eh);
	}
#endif
}

/** Initialize the kqueue engine
 */
void SocketEngine::Init()
{
	LookupMaxFds();
	RecoverFromFork();
}

void SocketEngine::RecoverFromFork()
{
	/*
	 * The only bad thing about kqueue is that its fd cant survive a fork and is not inherited.
	 * BUM HATS.
	 *
	 */
	EngineHandle = kqueue();
	if (EngineHandle == -1)
		InitError();
}

/** Shutdown the kqueue engine
 */
void SocketEngine::Deinit()
{
	Close(EngineHandle);
}

static struct kevent* GetChangeKE()
{
	if (ChangePos >= changelist.size())
		changelist.resize(changelist.size() * 2);
	return &changelist[ChangePos++];
}

bool SocketEngine::AddFd(EventHandler* eh, int event_mask)
{
	int fd = eh->GetFd();

	if (fd < 0)
		return false;

	if (!SocketEngine::AddFdRef(eh))
		return false;

	// We always want to read from the socket...
	struct kevent* ke = GetChangeKE();
	EV_SET(ke, fd, EVFILT_READ, EV_ADD, 0, 0, udata_cast(eh));

	ServerInstance->Logs.Log("SOCKET", LOG_DEBUG, "New file descriptor: %d", fd);

	eh->SetEventMask(event_mask);
	OnSetEvent(eh, 0, event_mask);
	ResizeDouble(ke_list);

	return true;
}

void SocketEngine::DelFd(EventHandler* eh)
{
	int fd = eh->GetFd();

	if (fd < 0)
	{
		ServerInstance->Logs.Log("SOCKET", LOG_DEFAULT, "DelFd() on invalid fd: %d", fd);
		return;
	}

	// First remove the write filter ignoring errors, since we can't be
	// sure if there are actually any write filters registered.
	struct kevent* ke = GetChangeKE();
	EV_SET(ke, eh->GetFd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL);

	// Then remove the read filter.
	ke = GetChangeKE();
	EV_SET(ke, eh->GetFd(), EVFILT_READ, EV_DELETE, 0, 0, NULL);

	SocketEngine::DelFdRef(eh);

	ServerInstance->Logs.Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d", fd);
}

void SocketEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
{
	if ((new_mask & FD_WANT_POLL_WRITE) && !(old_mask & FD_WANT_POLL_WRITE))
	{
		// new poll-style write
		struct kevent* ke = GetChangeKE();
		EV_SET(ke, eh->GetFd(), EVFILT_WRITE, EV_ADD, 0, 0, udata_cast(eh));
	}
	else if ((old_mask & FD_WANT_POLL_WRITE) && !(new_mask & FD_WANT_POLL_WRITE))
	{
		// removing poll-style write
		struct kevent* ke = GetChangeKE();
		EV_SET(ke, eh->GetFd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
	}
	if ((new_mask & (FD_WANT_FAST_WRITE | FD_WANT_SINGLE_WRITE)) && !(old_mask & (FD_WANT_FAST_WRITE | FD_WANT_SINGLE_WRITE)))
	{
		struct kevent* ke = GetChangeKE();
		EV_SET(ke, eh->GetFd(), EVFILT_WRITE, EV_ADD | EV_ONESHOT, 0, 0, udata_cast(eh));
	}
}

int SocketEngine::DispatchEvents()
{
	struct timespec ts;
	ts.tv_nsec = 0;
	ts.tv_sec = 1;

	int i = kevent(EngineHandle, &changelist.front(), ChangePos, &ke_list.front(), ke_list.size(), &ts);
	ChangePos = 0;
	ServerInstance->UpdateTime();

	if (i < 0)
		return i;

	stats.TotalEvents += i;

	for (int j = 0; j < i; j++)
	{
		// This can't be a static_cast because udata is intptr_t on NetBSD.
		struct kevent& kev = ke_list[j];
		EventHandler* eh = reinterpret_cast<EventHandler*>(kev.udata);
		if (!eh)
			continue;

		// Copy these in case the vector gets resized and kev invalidated
		const int fd = eh->GetFd();
		const short filter = kev.filter;
		if (fd < 0)
			continue;

		if (kev.flags & EV_EOF)
		{
			stats.ErrorEvents++;
			eh->OnEventHandlerError(kev.fflags);
			continue;
		}
		if (filter == EVFILT_WRITE)
		{
			/* When mask is FD_WANT_FAST_WRITE or FD_WANT_SINGLE_WRITE,
			 * we set a one-shot write, so we need to clear that bit
			 * to detect when it set again.
			 */
			const int bits_to_clr = FD_WANT_SINGLE_WRITE | FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK;
			eh->SetEventMask(eh->GetEventMask() & ~bits_to_clr);
			eh->OnEventHandlerWrite();
		}
		else if (filter == EVFILT_READ)
		{
			eh->SetEventMask(eh->GetEventMask() & ~FD_READ_WILL_BLOCK);
			eh->OnEventHandlerRead();
		}
	}

	return i;
}