<commit_before>/*
    kircclienteventhandler.cpp - IRC Client Message Handler

    Copyright (c) 2002      by <NAME> <<EMAIL>>
    Copyright (c) 2003      by <NAME> <<EMAIL>>
    Copyright (c) 2003-2006 by <NAME> <<EMAIL>>

    Kopete    (c) 2002-2006 by the Kopete developers <<EMAIL>>

    *************************************************************************
    *                                                                       *
    * This program 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; either version 2 of the License, or     *
    * (at your option) any later version.                                   *
    *                                                                       *
    *************************************************************************
*/

#include "kircclienthandler.moc"

#include "kircclientsocket.h"

#include "kirccontext.h"
#include "kircevent.h"

#include <kdebug.h>
#include <klocale.h>

#include <QDateTime>
#include <qfileinfo.h>
#include <qregexp.h>

#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>


// For now lets define it to be empty
#define CHECK_ARGS(min, max)

class KIrc::ClientEventHandlerPrivate
{
public:
	KIrc::Context *context;
};

using namespace KIrc;

ClientEventHandler::ClientEventHandler(Context *context, QObject* parent)
	: Handler(parent)
	, d_ptr(new ClientEventHandlerPrivate)
{
	Q_D(ClientEventHandler);

	d->context = context;
}

ClientEventHandler::~ClientEventHandler()
{
	delete d_ptr;
}

#if 0
void ClientEventHandler::postEvent(QEvent *event)
{
//	post the message here ... still dunno where, socket ?
}

bool ClientEventHandler::postEvent(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket, const QByteArray &eventId, Entity::Ptr &from, QString &text)
{
	Q_D(ClientEventHandler);

	Message message = ev->message();
	from = d->context->entityFromName(message.prefix());
	if (text.isEmpty())
		text = message.suffix();

	if (from) {
//		postEvent(new TextEvent(eventId, from, to, text));
		return true;
	}
	return false;
}

bool ClientEventHandler::postEvent(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket, const QByteArray &eventId, Entity::Ptr &from, Entity::List &to, QString &text)
{
	Q_D(ClientEventHandler);

	Message message = ev->message();
	from = d->context->entityFromName(message.prefix());
	to = d->context->entitiesFromNames(message.argAt(1));
	if (text.isEmpty())
		text = message.suffix();

	if (from && (to.count() > 0)) {
		postEvent(new TextEvent(eventId, from, to, text));
		return true;
	}
	return false;
}

bool ClientEventHandler::postEvent(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket, const QByteArray &eventId, Entity::Ptr &from, Entity::List &to, Entity::List &victims, QString &text)
{
	Q_D(ClientEventHandler);

	Message message = ev->message();
	from = d->context->entityFromName(message.prefix());
	to = d->context->entitiesFromNames(message.argAt(1));
	victims = d->context->entitiesFromNames(message.argAt(2));
	if (text.isEmpty())
		text = message.suffix();

	if (from && (to.count() > 0) && (victims.count() > 0)) {
		postEvent(new TextEvent(eventId, from, to, text));
		return true;
	}
	return false;
}

bool ClientEventHandler::postServerInfoEvent(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket)
{
	Entity::Ptr &from; Entity::List &to;
	return postEvent(ev, "ServerInfo", from, to);
}

/*
void ClientEventHandler::postEvent(const MessageEvent *&message, Event::MessageType messageType, const QString &message)
{
	Event event;
	event.setType(messageType);
//	event.setFrom(message.prefix());
//	event.setCc(message.socket().owner()); // server instead ?

	if (message.isEmpty())
		event.setMessage(message.suffix());
	else
		event.setMessage(message);

//	post the message here ... still dunno where, socket ?
}
*/

void ClientEventHandler::receivedServerMessage(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket, const QString &message)
{
}

#endif

void ClientEventHandler::receivedServerMessage(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket)
{
	KIrc::TextEvent *event=new KIrc::TextEvent( "ServerInfo",
												 static_cast<KIrc::ClientSocket*>( socket )->server(),
												 static_cast<KIrc::ClientSocket*>( socket )->server() ,
												 message.suffix()
											   );
	context->postEvent( event );
}


// FIXME: Really handle this message
KIrc::Handler::Handled ClientEventHandler::error(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket)
{
	CHECK_ARGS(0, 0);

//	message->client->close();
	return KIrc::Handler::NotHandled;
}

/* RFC say: "( <channel> *( "," <channel> ) [ <key> *( "," <key> ) ] ) / "0""
 * suspected: ":<channel> *(" "/"," <channel>)"
 * assumed ":<channel>"
 * This is the response of someone joining a channel.
 * Remember that this will be emitted when *you* /join a room for the first time
 */
KIrc::Handler::Handled ClientEventHandler::join(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket)<commit_msg>Simplify code by creating a temporary variable.<commit_after>/*
    kircclienteventhandler.cpp - IRC Client Message Handler

    Copyright (c) 2002      by <NAME> <<EMAIL>>
    Copyright (c) 2003      by <NAME> <<EMAIL>>
    Copyright (c) 2003-2006 by <NAME> <<EMAIL>>

    Kopete    (c) 2002-2006 by the Kopete developers <<EMAIL>>

    *************************************************************************
    *                                                                       *
    * This program 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; either version 2 of the License, or     *
    * (at your option) any later version.                                   *
    *                                                                       *
    *************************************************************************
*/

#include "kircclienthandler.moc"

#include "kircclientsocket.h"

#include "kirccontext.h"
#include "kircevent.h"

#include <kdebug.h>
#include <klocale.h>

#include <QDateTime>
#include <qfileinfo.h>
#include <qregexp.h>

#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>


// For now lets define it to be empty
#define CHECK_ARGS(min, max)

class KIrc::ClientEventHandlerPrivate
{
public:
	KIrc::Context *context;
};

using namespace KIrc;

ClientEventHandler::ClientEventHandler(Context *context, QObject* parent)
	: Handler(parent)
	, d_ptr(new ClientEventHandlerPrivate)
{
	Q_D(ClientEventHandler);

	d->context = context;
}

ClientEventHandler::~ClientEventHandler()
{
	delete d_ptr;
}

#if 0
void ClientEventHandler::postEvent(QEvent *event)
{
//	post the message here ... still dunno where, socket ?
}

bool ClientEventHandler::postEvent(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket, const QByteArray &eventId, Entity::Ptr &from, QString &text)
{
	Q_D(ClientEventHandler);

	Message message = ev->message();
	from = d->context->entityFromName(message.prefix());
	if (text.isEmpty())
		text = message.suffix();

	if (from) {
//		postEvent(new TextEvent(eventId, from, to, text));
		return true;
	}
	return false;
}

bool ClientEventHandler::postEvent(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket, const QByteArray &eventId, Entity::Ptr &from, Entity::List &to, QString &text)
{
	Q_D(ClientEventHandler);

	Message message = ev->message();
	from = d->context->entityFromName(message.prefix());
	to = d->context->entitiesFromNames(message.argAt(1));
	if (text.isEmpty())
		text = message.suffix();

	if (from && (to.count() > 0)) {
		postEvent(new TextEvent(eventId, from, to, text));
		return true;
	}
	return false;
}

bool ClientEventHandler::postEvent(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket, const QByteArray &eventId, Entity::Ptr &from, Entity::List &to, Entity::List &victims, QString &text)
{
	Q_D(ClientEventHandler);

	Message message = ev->message();
	from = d->context->entityFromName(message.prefix());
	to = d->context->entitiesFromNames(message.argAt(1));
	victims = d->context->entitiesFromNames(message.argAt(2));
	if (text.isEmpty())
		text = message.suffix();

	if (from && (to.count() > 0) && (victims.count() > 0)) {
		postEvent(new TextEvent(eventId, from, to, text));
		return true;
	}
	return false;
}

bool ClientEventHandler::postServerInfoEvent(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket)
{
	Entity::Ptr &from; Entity::List &to;
	return postEvent(ev, "ServerInfo", from, to);
}

/*
void ClientEventHandler::postEvent(const MessageEvent *&message, Event::MessageType messageType, const QString &message)
{
	Event event;
	event.setType(messageType);
//	event.setFrom(message.prefix());
//	event.setCc(message.socket().owner()); // server instead ?

	if (message.isEmpty())
		event.setMessage(message.suffix());
	else
		event.setMessage(message);

//	post the message here ... still dunno where, socket ?
}
*/

void ClientEventHandler::receivedServerMessage(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket, const QString &message)
{
}

#endif

void ClientEventHandler::receivedServerMessage(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket)
{
	KIrc::Entity *server = static_cast<KIrc::ClientSocket*>( socket )->server();
	KIrc::TextEvent *event=new KIrc::TextEvent( "ServerInfo", server, server, message.suffix() );
	context->postEvent( event );
}


// FIXME: Really handle this message
KIrc::Handler::Handled ClientEventHandler::error(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket)
{
	CHECK_ARGS(0, 0);

//	message->client->close();
	return KIrc::Handler::NotHandled;
}

/* RFC say: "( <channel> *( "," <channel> ) [ <key> *( "," <key> ) ] ) / "0""
 * suspected: ":<channel> *(" "/"," <channel>)"
 * assumed ":<channel>"
 * This is the response of someone joining a channel.
 * Remember that this will be emitted when *you* /join a room for the first time
 */
KIrc::Handler::Handled ClientEventHandler::join(KIrc::Context *context, const KIrc::Message &message, KIrc::Socket *socket)
{'fraction_non_alphanumeric': 0.17270114942528736, 'fraction_numerical': 0.006704980842911878, 'mean_word_length': 4.25730110775428, 'pattern_counts': {'":': 4, '<': 58, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3395362', 'n_tokens_mistral': 3380, 'n_tokens_neox': 3211, 'n_words': 824}