示例#1
0
QString GaduChatImageService::saveImage(UinType sender, uint32_t size, uint32_t crc32, const QString &fileName, const char *data)
{
	kdebugf();

	QString path = ggPath("images");
	kdebugm(KDEBUG_INFO, "Creating directory: %s\n", qPrintable(path));

	if (!QDir().mkdir(path))
	{
		kdebugm(KDEBUG_INFO, "Failed creating directory: %s\n", qPrintable(path));
		return QString::null;
	}

	QString file_name = QString("%1-%2-%3-%4").arg(sender).arg(size).arg(crc32).arg(fileName);
	kdebugm(KDEBUG_INFO, "Saving image as file: %s\n", qPrintable(fileName));

	SavedImage img;
	img.size = size;
	img.crc32 = crc32;
	img.fileName = path + '/' + fileName;

	QFile file(img.fileName);
	file.open(QIODevice::WriteOnly);
	file.write(data, size);
	file.close();

	SavedImages.append(img);

	return img.fileName;
}
示例#2
0
void XmlConfigFile::read()
{
	kdebugf();
	QFile file;
	QDir backups(ggPath(), "kadu.conf.xml.backup.*", QDir::Name, QDir::Files);
	QStringList files("kadu.conf.xml");
	files += backups.entryList();
	bool fileOpened(false);

	foreach(const QString &fileName, files)
	{
		file.setFileName(ggPath(fileName));
		fileOpened = file.open(QIODevice::ReadOnly);
		if (fileOpened && file.size() > 0)
		{
			kdebugm(KDEBUG_INFO, "configuration file %s opened!\n", qPrintable(file.fileName()));
			break;
		}
		if (fileOpened) // && file.size() == 0
		{
			kdebugm(KDEBUG_INFO, "config file (%s) is empty, looking for backup\n", qPrintable(file.fileName()));
			file.close();
			fileOpened = false;
		}
		else
			kdebugm(KDEBUG_INFO, "config file (%s) not opened, looking for backup\n", qPrintable(file.fileName()));
	}
示例#3
0
void GaduChatImageService::handleEventImageRequest(struct gg_event *e)
{
	kdebugm(KDEBUG_INFO, qPrintable(QString("Received image request. sender: %1, size: %2, crc32: %3\n")
		.arg(e->event.image_request.sender).arg(e->event.image_request.size).arg(e->event.image_request.crc32)));

	uint32_t size = e->event.image_request.size;
	uint32_t crc32 = e->event.image_request.crc32;

	if (!ImagesToSend.contains(qMakePair(size, crc32)))
	{
		kdebugm(KDEBUG_WARNING, "Image data not found\n");
		return;
	}

	ImageToSend &image = ImagesToSend[qMakePair(size, crc32)];
	if (image.content.isNull())
	{
		loadImageContent(image);
		if (image.content.isNull())
			return;
	}

	gg_image_reply(Protocol->gaduSession(), e->event.image_request.sender, qPrintable(image.fileName), image.content.constData(), image.content.length());

	image.content = QByteArray();
	image.lastSent = QDateTime::currentDateTime();
}
示例#4
0
bool EmoticonsManager::loadGGEmoticonThemePart(const QString &themeSubDirPath)
{
	QString dir = themeSubDirPath;

	if (!dir.isEmpty() && !dir.endsWith('/'))
		dir += '/';

	QFile theme_file(dir + "emots.txt");
	if (!theme_file.open(QIODevice::ReadOnly))
	{
		kdebugm(KDEBUG_FUNCTION_END|KDEBUG_WARNING, "Error opening %s file\n",
			qPrintable(theme_file.fileName()));
		return false;
	}
	QTextStream theme_stream(&theme_file);
	theme_stream.setCodec(codec_cp1250);
	while (!theme_stream.atEnd())
	{
		EmoticonsListItem item;
		QString line = theme_stream.readLine();
		kdebugm(KDEBUG_DUMP, "> %s\n", qPrintable(line));
		unsigned int lineLength = line.length();
		unsigned int i = 0;
		bool multi = false;
		QStringList aliases;
		if (i < lineLength && line.at(i) == '*')
			++i; // eat '*'
		if (i < lineLength && line.at(i) == '(')
		{
			multi = true;
			++i;
		}
		for (;;)
		{
			aliases.append(getQuoted(line, i));
			if (!multi || i >= lineLength || line.at(i) == ')')
				break;
			++i; // eat ','
		}
		if (multi)
			++i; // eat ')'
		++i; // eat ','
		item.anim = themeSubDirPath + '/' + fixFileName(themeSubDirPath, getQuoted(line, i));
		if (i < lineLength && line.at(i) == ',')
		{
			++i; // eat ','
			item.stat = themeSubDirPath + '/' + fixFileName(themeSubDirPath, getQuoted(line, i));
		}
		else
			item.stat = item.anim;

		foreach (const QString &alias, aliases)
		{
			item.alias = alias;
			Aliases.push_back(item);
		}

		item.alias = aliases.at(0);
		Selector.append(item);
	}
void PendingMessagesManager::deleteMsg(int index)
{
	kdebugm(KDEBUG_INFO, "PendingMessagesManager::(pre)deleteMsg(%d), count=%d\n", index, count());
	Contact e = msgs[index].sender();
	msgs.removeAt(index);
	storeConfiguration(xml_config_file);
	kdebugm(KDEBUG_INFO, "PendingMessagesManager::deleteMsg(%d), count=%d\n", index, count());
	emit messageFromUserDeleted(e);
}
示例#6
0
QString GaduChatImageService::getSavedImageFileName(uint32_t size, uint32_t crc32)
{
	kdebugf();
	kdebugm(KDEBUG_INFO, "Searching saved images: size=%u, crc32=%u\n", size, crc32);

	foreach (const SavedImage &image, SavedImages)
		if (image.size == size && image.crc32 == crc32)
			return image.fileName;

	kdebugm(KDEBUG_WARNING, "Image data not found\n");
	return QString::null;
}
示例#7
0
//#include <sys/time.h>
void PlainConfigFile::write() const
{
	kdebugf();

/*	struct timeval t1,t2;
	gettimeofday(&t1, NULL);
	for(int j=0; j<100; ++j)
	{*/

	QFile file(filename);
	QString line;
	QStringList out;
	QString format1("[%1]\n");
	QString format2("%1=%2\n");

	if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
	{
		kdebugm(KDEBUG_INFO, "file opened '%s'\n", qPrintable(file.fileName()));
		QTextStream stream(&file);
		stream.setCodec(codec_latin2);
		foreach(const QString &key, groups.keys())
		{
//			kdebugm(KDEBUG_DUMP, ">> %s\n", (i.key()));
			out.append(format1.arg(key));
			foreach(const QString &dataKey, groups[key].keys())
			{
				QString q = groups[key][dataKey];
				out.append(format2.arg(dataKey).arg(q.replace('\n', "\\n")));
//				kdebugm(KDEBUG_DUMP, ">>>>> %s %s\n", qPrintable(key()), qPrintable(q));
			}
			out.append("\n");
		}
		stream << out.join(QString::null);
		file.close();
	}
示例#8
0
QString GaduProtocolHelper::connectionErrorMessage(GaduProtocol::GaduError error)
{
	switch (error)
	{
		case GaduProtocol::ConnectionServerNotFound:
			return QCoreApplication::translate("@default", "Unable to connect, server has not been found");
		case GaduProtocol::ConnectionCannotConnect:
			return QCoreApplication::translate("@default", "Unable to connect");
		case GaduProtocol::ConnectionNeedEmail:
			return QCoreApplication::translate("@default", "Please change your email in \"Change password / email\" window. Leave new password field blank.");
		case GaduProtocol::ConnectionInvalidData:
			return QCoreApplication::translate("@default", "Unable to connect, server has returned unknown data");
		case GaduProtocol::ConnectionCannotRead:
			return QCoreApplication::translate("@default", "Unable to connect, connection break during reading");
		case GaduProtocol::ConnectionCannotWrite:
			return QCoreApplication::translate("@default", "Unable to connect, connection break during writing");
		case GaduProtocol::ConnectionIncorrectPassword:
			return QCoreApplication::translate("@default", "Unable to connect, invalid password");
		case GaduProtocol::ConnectionTlsError:
			return QCoreApplication::translate("@default", "Unable to connect, error of negotiation TLS");
		case GaduProtocol::ConnectionIntruderError:
			return QCoreApplication::translate("@default", "Too many connection attempts with bad password!");
		case GaduProtocol::ConnectionUnavailableError:
			return QCoreApplication::translate("@default", "Unable to connect, servers are down");
		case GaduProtocol::ConnectionUnknow:
			return QCoreApplication::translate("@default", "Connection broken");
		case GaduProtocol::ConnectionTimeout:
			return QCoreApplication::translate("@default", "Connection timeout!");
		case GaduProtocol::Disconnected:
			return QCoreApplication::translate("@default", "Disconnection has occurred");
		default:
			kdebugm(KDEBUG_ERROR, "Unhandled error? (%d)\n", int(error));
			return QCoreApplication::translate("@default", "Connection broken");
	}
}
示例#9
0
void OSSPlayerSlots::playSample(SoundDevice device, const qint16 *data, int length, bool *result)
{
	kdebugf();

	*result = true;
	OSSSoundDevice* dev = (OSSSoundDevice*)device;
	if (!dev || dev->fd<0)
	{
		*result = false;
		kdebugm(KDEBUG_WARNING, "cannot play sample, device not opened, dev:%p dev->fd:%d\n", dev, dev?dev->fd:-1);
		return;
	}
	write_all(dev->fd, (char*)data, length, dev->max_buf_size);

	if (dev->flushing)
	{
		// wait for end of playing
		if (ioctl(dev->fd, SNDCTL_DSP_SYNC, 0) < 0)
		{
			fprintf(stderr, "SNDCTL_DSP_SYNC error (%s, %d)\n", strerror(errno), errno);
			*result = false;
		}
	}
	kdebugf2();
}
示例#10
0
void PowerStatusChanger::changeStatus(UserStatus &status)
{
    kdebugf();
    switch(state)
    {
    case STATUS_ONLINE:
        status.setOnline(description);
        break;

    case STATUS_BUSY:
        status.setBusy(description);
        break;

    case STATUS_INVISIBLE:
        status.setInvisible(description);
        break;

    case STATUS_OFFLINE:
        status.setOffline(description);
        break;

    case STATUS_BY_INDEX:
        status.setIndex(index, description);

    default:
        kdebugm(KDEBUG_INFO, "Status state not specified\n");
        break;
    }
    state = STATUS_NOT_SPECIFIED;
    kdebugf2();
}
示例#11
0
bool Filtering::on_kadu_keyPressed (QKeyEvent *e)
{
//	kdebugf();
#ifndef Q_OS_MAC
	QString text = e->text ();
	kdebugm (KDEBUG_INFO, QString("text=[%1] key=%2\n").arg (e->text ()).arg (e->key ()).local8Bit ());
	
	bool startonany = config_file.readBoolEntry ("filtering", "filter-startonany", false);
	bool shortcut = HotKey::shortCut (e, "ShortCuts", "filtering_start");

	if (shortcut || (startonany && (text.ref (0).isPrint ())) && kadu->userbox ()->count ()) {
		show ();
		textLE->setFocus ();
		if (startonany && (! shortcut)) {
			textLE->setText (text);
		}
	    return true;
	} else if (e->key () == Qt::Key_Escape && isVisible()) {
	    hideFilter ();
	    return true;
	} else {
	    return false;
	}
#endif	
//	kdebugf2();
}
示例#12
0
文件: agent.cpp 项目: ziemniak/kadu
Agent::Agent() : QObject(NULL, "agent")
{
	kdebugf();

	connect(gadu, SIGNAL(userStatusChangeIgnored(UinType)), this, SLOT(userFound(UinType)));

	// Main menu entry
	agentActionDescription = new ActionDescription(
		ActionDescription::TypeMainMenu, "agentAction",
		this, SLOT(resultsRequest()),
		"Agent", tr("Who has me on list")
	);
	kadu->insertMenuActionDescription(0, agentActionDescription);

	if(config_file.readBoolEntry("Agent", "FirstTime", true))
	{
		QFile listFile;
		listFile.setName(QString(ggPath("spy-unknownslist").ascii()));
		if(listFile.open(IO_ReadOnly))
		{
			if(MessageBox::ask(tr("Agent has founded spy's unknown-users list. Do you want to append this list to agent module?")))
			{
				QTextStream stream(&listFile);

				QString uin_str, date_str, line;
				bool ok;
				while (!stream.atEnd())
				{
					UnknownUser user;
					bool isAlready = false;

					line = stream.readLine();
					uin_str = line.section(',', 0, 0);
					date_str = line.section(',', 1, 1);

					unsigned int uin_int = uin_str.toUInt(&ok, 10);
					if(!ok)
						kdebugm(KDEBUG_PANIC, "Couldn't cast QString to int");

					foreach(UnknownUser user, UnknownsList)
					{
						if (user.uin == uin_int)
						{
							isAlready = true;
							break;
						}
					}
					if (!isAlready)
					{
						user.uin = uin_int;
						user.date = QDate::fromString(date_str, Qt::ISODate);
						user.seq = 0;
						UnknownsList.append(user);
					}
				}
			}
			listFile.close();
		}
示例#13
0
void SoundFile::loadData(const QString &path)
{
#ifndef Q_OS_WIN
	SF_INFO info;
	memset(&info, 0, sizeof(info));
	SNDFILE *f = sf_open(path.toUtf8().constData(), SFM_READ, &info);
	if (!f)
	{
		fprintf(stderr, "cannot open file '%s'\n", qPrintable(path));
		return;
	}

	kdebugm(KDEBUG_INFO, "frames:\t\t%llu\n", (long long unsigned)info.frames);
	kdebugm(KDEBUG_INFO, "samplerate:\t%d\n", info.samplerate);
	kdebugm(KDEBUG_INFO, "channels:\t%d\n", info.channels);
	kdebugm(KDEBUG_INFO, "format:\t\t0x%x\n", info.format);
	kdebugm(KDEBUG_INFO, "sections:\t%d\n", info.sections);
	kdebugm(KDEBUG_INFO, "seekable:\t%d\n", info.seekable);

	Length = info.frames * info.channels;
	Channels = info.channels;
	SampleRate = info.samplerate;

	Data = new short int[Length];

	long format = info.format & SF_FORMAT_SUBMASK;

	if (format == SF_FORMAT_FLOAT || format == SF_FORMAT_DOUBLE)
		loadFloatSamples(f);
	else
		loadIntSamples(f);

	sf_close(f);
#endif
}
示例#14
0
void GaduChatImageService::loadImageContent(ImageToSend &image)
{
	QFile imageFile(image.fileName);
	if (!imageFile.open(QIODevice::ReadOnly))
	{
		image.content = QByteArray();
		kdebugm(KDEBUG_ERROR, "Error opening file\n");
		return;
	}

	QByteArray data = imageFile.readAll();
	imageFile.close();

	if (data.length() != imageFile.size())
	{
		image.content = QByteArray();
		kdebugm(KDEBUG_ERROR, "Error reading file\n");
		return;
	}

	image.content = data;
}
示例#15
0
void GaduChatImageService::handleEventImageReply(struct gg_event *e)
{
	kdebugm(KDEBUG_INFO, qPrintable(QString("Received image. sender: %1, size: %2, crc32: %3,filename: %4\n")
			.arg(e->event.image_reply.sender).arg(e->event.image_reply.size)
			.arg(e->event.image_reply.crc32).arg(e->event.image_reply.filename)));

	QString fullPath = saveImage(e->event.image_reply.sender,
			e->event.image_reply.size, e->event.image_reply.crc32,
			e->event.image_reply.filename, e->event.image_reply.image);
	if (fullPath.isNull())
		return;

	emit imageReceived(GaduFormater::createImageId(e->event.image_reply.sender,
			e->event.image_reply.size, e->event.image_reply.crc32), fullPath);
}
示例#16
0
void OSSPlayerSlots::closeDevice(SoundDevice device)
{
	kdebugf();
	OSSSoundDevice* dev = (OSSSoundDevice*)device;
	if (!dev)
	{
		kdebugm(KDEBUG_WARNING, "cannot close device, device not opened\n");
		return;
	}
	if (dev->fd!=-1)
	{
		close(dev->fd);
		dev->fd = -1;
	}
	delete dev;
	device = NULL;
	kdebugf2();
}
示例#17
0
void SmsDialog::sendSms()
{
	kdebugf();

	SmsSender *sender;

	if (m_configuration->deprecatedApi()->readBoolEntry("SMS", "BuiltInApp"))
	{
		int gatewayIndex = ProviderComboBox->currentIndex();
		QString gatewayId = ProviderComboBox->itemData(gatewayIndex, Qt::UserRole).toString();
		sender = m_pluginInjectedFactory->makeInjected<SmsInternalSender>(m_smsGatewayManager, m_smsScriptsManager, RecipientEdit->text(), m_smsGatewayManager->byId(gatewayId), this);
	}
	else
	{
		if (m_configuration->deprecatedApi()->readEntry("SMS", "SmsApp").isEmpty())
		{
			MessageDialog::show(m_iconsManager->iconByPath(KaduIcon("dialog-warning")), tr("Kadu"),
					tr("SMS application was not specified. Visit the configuration section"), QMessageBox::Ok, this);
			kdebugm(KDEBUG_WARNING, "SMS application NOT specified. Exit.\n");
			return;
		}
		sender = m_pluginInjectedFactory->makeInjected<SmsExternalSender>(RecipientEdit->text(), this);
	}

	connect(sender, SIGNAL(gatewayAssigned(QString, QString)), this, SLOT(gatewayAssigned(QString, QString)));
	sender->setSignature(SignatureEdit->text());

	auto window = m_pluginInjectedFactory->makeInjected<ProgressWindow>(tr("Sending SMS..."));
	window->setCancellable(true);
	window->show();

	connect(window, SIGNAL(canceled()), sender, SLOT(cancel()));
	connect(sender, SIGNAL(canceled()), window, SLOT(reject()));

	connect(sender, SIGNAL(progress(QString,QString)), window, SLOT(addProgressEntry(QString,QString)));
	connect(sender, SIGNAL(finished(bool,QString,QString)), window, SLOT(progressFinished(bool,QString,QString)));

	if (SaveInHistoryCheckBox->isChecked())
		connect(sender, SIGNAL(smsSent(QString,QString)), this, SLOT(saveSmsInHistory(QString,QString)));

	sender->sendMessage(ContentEdit->toPlainText());

	kdebugf2();
}
示例#18
0
文件: infos.cpp 项目: partition/kadu
Infos::Infos(QObject *parent) :
	QObject(parent)
{
	kdebugf();

	triggerAllAccountsRegistered();

	fileName = profilePath("last_seen.data");

	if (QFile::exists(fileName))
	{
		QFile file(fileName);
		if (file.open(QIODevice::ReadOnly))
		{
			kdebugm(KDEBUG_INFO, "file opened '%s'\n", qPrintable(file.fileName()));
			QTextStream stream(&file);
			while (!stream.atEnd())
			{
				QStringList fullId = stream.readLine().split(':', QString::SkipEmptyParts);
				if (fullId.count() != 2)
					continue;
				QString protocol = fullId[0];
				QString uin = fullId[1];
				QString dateTime = stream.readLine();
				//kdebugm(KDEBUG_INFO, "Last seen %s %s %s\n", qPrintable(protocol), qPrintable(uin), qPrintable(dateTime));

				Contact contact;
				// wstawiamy tylko konta, które są na liście kontaktów
				foreach(Account account, AccountManager::instance()->byProtocolName(protocol))
				{
					contact = ContactManager::instance()->byId(account, uin, ActionReturnNull);
					if (contact.isNull())
						continue;
					if (!contact.ownerBuddy().isAnonymous())
					{
						lastSeen[qMakePair(protocol, uin)] = dateTime;
						// wystarczy, że kontakt jest na jednym koncie, omijamy resztę
						continue;
					}
				}
				QString tmp = stream.readLine(); // skip empty line
			}
			file.close();
		}
示例#19
0
void MacOSXDocking::trayPixmapChanged(const QIcon &small_pix, const QString &name)
{
	if (!config_file.readBoolEntry("MacOSX Dock", "IconNotification", true))
		return;

	const QIcon &pix = IconsManager::instance()->loadIcon("Big" + name);
	if (pix.isNull())
	{
		kdebugm(KDEBUG_WARNING, "big icon of %s not available\n", qPrintable(name));
		pixmap = small_pix.pixmap(128,128);
	}
	else
	{
		pixmap = pix.pixmap(128,128);
	}

	kadu->setIcon(pixmap);
	qApp->setWindowIcon(pixmap);
}
示例#20
0
文件: split.cpp 项目: ziemniak/kadu
void Split::onMessageSendRequested(ChatWidget *chat)
{
	kdebugf();

	if (!config_file.readBoolEntry("PowerKadu", "enable_split_message", false))
		return;

	const unsigned int maxL = 1000;
	unsigned int length;
	unsigned char *format;
	QTextDocument doc;
	QString text = chat->edit()->text();
	text.replace("\n", "\r\n");
	doc.setHtml(text);
	text = doc.toPlainText();
	text.replace("\r\n", "\n");
	kdebugm(KDEBUG_INFO, "Tekst: %s\n", text.latin1());
	QStringList splitedMessages;
	if(text.length() > maxL)
	{
		unsigned int pos = 0;
		QString tmpStr;
		while(pos < text.length())
		{
			tmpStr = text.mid(pos, maxL);
			if(tmpStr != "")
				splitedMessages += tmpStr;
			pos += maxL;
		}
		fillEditor(chat, splitedMessages);
		
		SendSplitted *send = new SendSplitted(chat, splitedMessages, this, "send_splited");
		send->name();
	}
	kdebugf2();
}
示例#21
0
static void kadu_signal_handler(int signal)
{
	kdebugmf(KDEBUG_WARNING, "%d\n", signal);

	static int sigsegvCount = 0;

	if (sigsegvCount > 1)
	{
		kdebugmf(KDEBUG_WARNING, "sigsegv recursion: %d\n", sigsegvCount);
		abort();
	}

	if (signal == SIGSEGV)
	{
		++sigsegvCount;
		kdebugm(KDEBUG_PANIC, "Kadu crashed :(\n");

		CrashAwareObject::notifyCrash();

		QString backupFileName = QString("kadu.conf.xml.backup.%1").arg(QDateTime::currentDateTime().toString("yyyy.MM.dd.hh.mm.ss"));
		QString backtraceFileName = QString("kadu.backtrace.%1").arg(QDateTime::currentDateTime().toString("yyyy.MM.dd.hh.mm.ss"));

#ifdef HAVE_EXECINFO
		void *backtraceArray[100];
		char **backtraceStrings;
		int numEntries;

		if ((numEntries = backtrace(backtraceArray, 100)) < 0)
		{
			kdebugm(KDEBUG_PANIC, "could not generate backtrace\n");
			abort();
		}
		if (!(backtraceStrings = backtrace_symbols(backtraceArray, numEntries)))
		{
			kdebugm(KDEBUG_PANIC, "could not get symbol names for backtrace\n");
			abort();
		}

		fprintf(stderr, "\n======= BEGIN OF BACKTRACE =====\n");
		for (int i = 0; i < numEntries; ++i)
			fprintf(stderr, "[%d] %s\n", i, backtraceStrings[i]);
		fprintf(stderr, "======= END OF BACKTRACE  ======\n");
		fflush(stderr);

		FILE *backtraceFile = fopen(qPrintable(profilePath(backtraceFileName)), "w");
		if (backtraceFile)
		{
			fprintf(backtraceFile, "======= BEGIN OF BACKTRACE =====\n");
			for (int i = 0; i < numEntries; ++i)
				fprintf(backtraceFile, "[%d] %s\n", i, backtraceStrings[i]);
			fprintf(backtraceFile, "======= END OF BACKTRACE  ======\n");

			fprintf(backtraceFile, "static modules:\n");
			QStringList modules = ModulesManager::instance()->staticModules();

			foreach (const QString &module, modules)
				fprintf(backtraceFile, "> %s\n", qPrintable(module));

			fprintf(backtraceFile, "loaded modules:\n");
			modules = ModulesManager::instance()->loadedModules();
			foreach (const QString &module, modules)
				fprintf(backtraceFile, "> %s\n", qPrintable(module));
			fprintf(backtraceFile, "Kadu version: %s\n", qPrintable(Core::version()));
			fprintf(backtraceFile, "Qt compile time version: %s\nQt runtime version: %s\n",
					QT_VERSION_STR, qVersion());
#ifdef __GNUC__
			fprintf(backtraceFile, "GCC version: %d.%d.%d\n",
					__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#endif // __GNUC__
			fprintf(backtraceFile, "EOF\n");

			fclose(backtraceFile);
		}

		free(backtraceStrings);
#else // HAVE_EXECINFO
		kdebugm(KDEBUG_PANIC, "backtrace not available\n");
#endif // HAVE_EXECINFO

		xml_config_file->saveTo(profilePath(backupFileName.toLatin1()));
		abort();
	}
示例#22
0
static void kadu_signal_handler(int signal)
{
	kdebugmf(KDEBUG_WARNING, "%d\n", signal);

	static int sigsegvCount = 0;

	if (sigsegvCount > 1)
	{
		kdebugmf(KDEBUG_WARNING, "sigsegv recursion: %d\n", sigsegvCount);
		abort();
	}

	if (signal == SIGSEGV)
	{
		++sigsegvCount;
		kdebugm(KDEBUG_PANIC, "Kadu crashed :(\n");

		CrashAwareObject::notifyCrash();

		QString backtraceFileName = QStringLiteral("kadu.backtrace.") + QDateTime::currentDateTime().toString("yyyy.MM.dd.hh.mm.ss");

#if HAVE_EXECINFO
		void *backtraceArray[100];
		char **backtraceStrings;
		int numEntries;

		if ((numEntries = backtrace(backtraceArray, 100)) < 0)
		{
			kdebugm(KDEBUG_PANIC, "could not generate backtrace\n");
			abort();
		}
		if (!(backtraceStrings = backtrace_symbols(backtraceArray, numEntries)))
		{
			kdebugm(KDEBUG_PANIC, "could not get symbol names for backtrace\n");
			abort();
		}

		fprintf(stderr, "\n======= BEGIN OF BACKTRACE =====\n");
		for (int i = 0; i < numEntries; ++i)
			fprintf(stderr, "[%d] %s\n", i, backtraceStrings[i]);
		fprintf(stderr, "======= END OF BACKTRACE  ======\n");
		fflush(stderr);

		FILE *backtraceFile = fopen(qPrintable(QString(g_pathsProvider->profilePath() + backtraceFileName)), "w");
		if (backtraceFile)
		{
			fprintf(backtraceFile, "======= BEGIN OF BACKTRACE =====\n");
			for (int i = 0; i < numEntries; ++i)
				fprintf(backtraceFile, "[%d] %s\n", i, backtraceStrings[i]);
			fprintf(backtraceFile, "======= END OF BACKTRACE  ======\n");

			fprintf(backtraceFile, "loaded plugins:\n");
			auto pluginNames = g_pluginActivationService->activePlugins();
			for (auto const &pluginName : pluginNames)
				fprintf(backtraceFile, "> %s\n", qPrintable(pluginName));
			fprintf(backtraceFile, "Kadu version: %s\n", qPrintable(g_versionService->version()));
			fprintf(backtraceFile, "Qt compile time version: %s\nQt runtime version: %s\n",
					QT_VERSION_STR, qVersion());
#ifdef __GNUC__
			fprintf(backtraceFile, "GCC version: %d.%d.%d\n",
					__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#endif // __GNUC__
			fprintf(backtraceFile, "EOF\n");

			fclose(backtraceFile);
		}

		free(backtraceStrings);
#else // HAVE_EXECINFO
		kdebugm(KDEBUG_PANIC, "backtrace not available\n");
#endif // HAVE_EXECINFO

		g_application->backupConfiguration();
		abort();
	}
	else if (signal == SIGUSR1)
	{
		kdebugm(KDEBUG_INFO, "ok, got a signal to show up\n");
		_activateWindow(g_configuration, g_kaduWindowService->kaduWindow());
	}
	else if (signal == SIGINT || signal == SIGTERM)
		QCoreApplication::quit();
}
示例#23
0
bool Firewall::checkChat(const Chat &chat, const Contact &sender, const QString &message, bool &ignore)
{
    kdebugf();

    if (!CheckChats)
        return false;

    // konferencja
    if (chat.contacts().count() > 1)
    {
        kdebugf2();
        return false;
    }

    if (!sender.ownerBuddy().isAnonymous() || Passed.contains(sender))
    {
        kdebugf2();
        return false;
    }

    if (chat.chatAccount().statusContainer()->status().type() == "Invisible" && DropAnonymousWhenInvisible)
    {
        writeLog(sender, tr("Chat with anonim silently dropped.\n") + "----------------------------------------------------\n");

        kdebugf2();
        return true;
    }

    if (IgnoreInvisible)
    {
        if (sender.currentStatus().isDisconnected())
        {
            QDateTime *dateTime = chat.chatAccount().data()->moduleData<QDateTime>("firewall-account-connected");
            if (dateTime && (*dateTime < QDateTime::currentDateTime()))
            {
                Protocol *protocol = chat.chatAccount().protocolHandler();
                if (!protocol)
                {
                    kdebugf2();
                    return false;
                }

                ChatService *chatService = protocol->chatService();
                if (!chatService)
                {
                    kdebugf2();
                    return false;
                }

                chatService->sendMessage(chat, tr("This message has been generated AUTOMATICALLY!\n\nI'm a busy person and I don't have time for stupid chats with the persons hiding itself. If you want to talk with me change the status to Online or Busy first."), true);
            }

            writeLog(sender, tr("Chat with invisible anonim ignored.\n") + "----------------------------------------------------\n");

            kdebugf2();
            return true;
        }
    }

    if (pattern.exactMatch(message.simplified()))
    {
        Passed.insert(sender);

        if (Confirmation)
        {
            Protocol *protocol = chat.chatAccount().protocolHandler();
            if (!protocol)
            {
                kdebugf2();
                return false;
            }

            ChatService *chatService = protocol->chatService();
            if (!chatService)
            {
                kdebugf2();
                return false;
            }

            chatService->sendMessage(chat, ConfirmationText, true);
        }

        writeLog(sender, tr("User wrote right answer!\n") + "----------------------------------------------------\n");

        ignore = true;

        kdebugf2();
        return false;
    }
    else
    {
        if (LastContact != sender && Search)
        {
            SearchWindow *sd = new SearchWindow(Core::instance()->kaduWindow(), sender.ownerBuddy());
            sd->show();
            sd->firstSearch();

            LastContact = sender;
        }

        kdebugm(KDEBUG_INFO, "%s\n", qPrintable(message));

        QDateTime *dateTime = chat.chatAccount().data()->moduleData<QDateTime>("firewall-account-connected");

        if (dateTime && (*dateTime < QDateTime::currentDateTime()))
        {
            Protocol *protocol = chat.chatAccount().protocolHandler();
            if (!protocol)
            {
                kdebugf2();
                return false;
            }

            ChatService *chatService = protocol->chatService();
            if (!chatService)
            {
                kdebugf2();
                return false;
            }

            chatService->sendMessage(chat, ConfirmationQuestion, true);
        }

        kdebugf2();
        return true;
    }
}
示例#24
0
void OSSPlayerSlots::openDevice(SoundDeviceType type, int sample_rate, int channels, SoundDevice* device)
{
	kdebugf();
	int maxbufsize = 0, caps = 0, value;
	*device = NULL;

	QString sdev = config_file.readEntry("Sounds","OutputDevice", "/dev/dsp");
	kdebugm(KDEBUG_INFO, "Opening %s\n", qPrintable(sdev));

	int flags;
	if (type == SoundDevicePlayOnly)
		flags = O_WRONLY;
	else
		flags = O_RDWR;

	int fd = open(qPrintable(sdev), flags);
	if (fd < 0)
	{
		fprintf(stderr, "Error opening device (%s, %d)\n", strerror(errno), errno);
		return;
	}

	kdebugm(KDEBUG_INFO, "Resetting\n");
	if (ioctl(fd, SNDCTL_DSP_RESET, 0) < 0)
	{
		fprintf(stderr, "Error resetting (%s, %d)\n", strerror(errno), errno);
		close(fd);
		return;
	}

	// WARNING: parameters FORMAT, CHANNELS, SPEED must be set in that order
	// because of compatibility with some (old) soundcards
	kdebugm(KDEBUG_INFO, "Setting format\n");
	value = AFMT_S16_LE;
	if (ioctl(fd, SNDCTL_DSP_SETFMT, &value) < 0)
	{
		fprintf(stderr, "Error setting format (%s, %d)\n", strerror(errno), errno);
		close(fd);
		return;
	}

	kdebugm(KDEBUG_INFO, "Setting channels\n");
	value = channels;
	if (ioctl(fd, SNDCTL_DSP_CHANNELS, &value) < 0)
	{
		fprintf(stderr, "Error setting channels (%s, %d)\n", strerror(errno), errno);
		close(fd);
		return;
	}

	kdebugm(KDEBUG_INFO, "Setting speed\n");
	value = sample_rate;
	if (ioctl(fd, SNDCTL_DSP_SPEED, &value) < 0)
	{
		fprintf(stderr, "Error setting speed (%s, %d)\n", strerror(errno), errno);
		close(fd);
		return;
	}

	kdebugm(KDEBUG_INFO, "getting buffer size\n");
	if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &maxbufsize) < 0)
	{
		fprintf(stderr, "Error getting max buffer size (%s, %d)\n", strerror(errno), errno);
		close(fd);
		return;
	}

	kdebugm(KDEBUG_INFO, "checking capabilities\n");
	if (ioctl(fd, SNDCTL_DSP_GETCAPS, &caps) < 0)
	{
		fprintf(stderr, "Error getting capabilities (%s, %d)\n", strerror(errno), errno);
		close(fd);
		return;
	}
	else
	{
#if defined(DSP_CAP_MULTI) && defined(DSP_CAP_BIND)
		kdebugm(KDEBUG_INFO, "soundcard capabilities: rev=%d, duplex=%d, "
						"realtime=%d, batch=%d, coproc=%d, trigger=%d, "
						"mmap=%d, multi=%d, bind=%d\n",
			caps&DSP_CAP_REVISION, (caps&DSP_CAP_DUPLEX)!=0, (caps&DSP_CAP_REALTIME)!=0,
			(caps&DSP_CAP_BATCH)!=0, (caps&DSP_CAP_COPROC)!=0, (caps&DSP_CAP_TRIGGER)!=0,
			(caps&DSP_CAP_MMAP)!=0, (caps&DSP_CAP_MULTI)!=0, (caps&DSP_CAP_BIND)!=0);
#endif
	}


	kdebugm(KDEBUG_FUNCTION_END, "Setup successful, fd=%d maxbuf=%d\n", fd, maxbufsize);
	OSSSoundDevice* dev = new OSSSoundDevice;
	dev->fd = fd;
	dev->max_buf_size = maxbufsize;
	dev->sample_rate = sample_rate;
	dev->channels = channels;
	dev->flushing = false;
	*device = (SoundDevice) dev;
}