コード例 #1
0
void KBattleshipClient::slotReadData()
{
	int len;
	ioctl(fd(), FIONREAD, &len);
	if(!len)
	{
		delete m_readNotifier;
		m_readNotifier = 0;
		emit sigEndConnect();
		return;
	}

	char *buf = new char[len + 1];
	readBlock(buf, len);
	buf[len] = 0;
	m_readBuffer += QString::fromUtf8(buf);
	delete []buf;
	int pos;
	while ((pos = m_readBuffer.find("</kmessage>")) >= 0)
	{
		pos += 11; // Length of "</kmessage>"
		KMessage *msg = new KMessage();
		msg->setDataStream(m_readBuffer.left(pos));
		m_readBuffer.remove(0, pos);
		emit sigNewMessage(msg);
	}
}
コード例 #2
0
void KBattleshipWindow::slotSendVersion()
{
	KMessage *msg = new KMessage(KMessage::GETVERSION);
	msg->versionMessage();
	slotSendMessage(msg);

	QTimer::singleShot(150, this, SLOT(slotSendGreet()));
}
コード例 #3
0
void KBattleshipWindow::slotSendGreet()
{
	m_serverHasClient = true;
	m_chat->slotAcceptMsg(true);

	KMessage *msg = new KMessage(KMessage::GREET);
	msg->addField(QString("nickname"), m_ownNickname);
	slotSendMessage(msg);
}
コード例 #4
0
void KBattleshipWindow::slotSendChatMessage(const QString &text)
{
	if(m_connection != 0 && m_serverHasClient)
	{
		KMessage *msg = new KMessage(KMessage::CHAT);
		msg->chatMessage(m_ownNickname, text);
		slotSendMessage(msg);
	}
}
コード例 #5
0
ファイル: launch.cpp プロジェクト: kodybrown/haiku
status_t
BPrivate::send_request_to_launch_daemon(KMessage& request, KMessage& reply)
{
	status_t status = request.SendTo(get_launch_daemon_port(),
		B_PREFERRED_TOKEN, &reply);
	if (status != B_OK)
		return status;

	return (status_t)reply.What();
}
コード例 #6
0
ファイル: MessageAdapter.cpp プロジェクト: mariuz/haiku
status_t
MessageAdapter::_ConvertKMessage(const KMessage *fromMessage,
	BMessage *toMessage)
{
	if (!fromMessage || !toMessage)
		return B_BAD_VALUE;

	// make empty and init what of the target message
	toMessage->MakeEmpty();
	toMessage->what = fromMessage->What();

	BMessage::Private toPrivate(toMessage);
	toPrivate.SetTarget(fromMessage->TargetToken());
	toPrivate.SetReply(B_SYSTEM_TEAM, fromMessage->ReplyPort(),
		fromMessage->ReplyToken());

	// iterate through the fields and import them in the target message
	KMessageField field;
	while (fromMessage->GetNextField(&field) == B_OK) {
		int32 elementCount = field.CountElements();
		if (elementCount > 0) {
			for (int32 i = 0; i < elementCount; i++) {
				int32 size;
				const void *data = field.ElementAt(i, &size);
				status_t result;

				if (field.TypeCode() == B_MESSAGE_TYPE) {
					// message type: if it's a KMessage, convert it
					KMessage message;
					if (message.SetTo(data, size) == B_OK) {
						BMessage bMessage;
						result = _ConvertKMessage(&message, &bMessage);
						if (result < B_OK)
							return result;

						result = toMessage->AddMessage(field.Name(), &bMessage);
					} else {
						// just add it
						result = toMessage->AddData(field.Name(),
							field.TypeCode(), data, size,
							field.HasFixedElementSize(), 1);
					}
				} else {
					result = toMessage->AddData(field.Name(), field.TypeCode(),
						data, size, field.HasFixedElementSize(), 1);
				}

				if (result < B_OK)
					return result;
			}
		}
	}

	return B_OK;
}
コード例 #7
0
ファイル: port.cpp プロジェクト: mariuz/haiku
void
PortNotificationService::Notify(uint32 opcode, port_id port)
{
	char eventBuffer[64];
	KMessage event;
	event.SetTo(eventBuffer, sizeof(eventBuffer), PORT_MONITOR);
	event.AddInt32("event", opcode);
	event.AddInt32("port", port);

	DefaultNotificationService::Notify(event, opcode);
}
コード例 #8
0
	void Notify(uint32 eventCode, struct image* image)
	{
		char eventBuffer[128];
		KMessage event;
		event.SetTo(eventBuffer, sizeof(eventBuffer), IMAGE_MONITOR);
		event.AddInt32("event", eventCode);
		event.AddInt32("image", image->info.id);
		event.AddPointer("imageStruct", image);

		DefaultNotificationService::Notify(event, eventCode);
	}
コード例 #9
0
status_t
NotificationManager::UpdateListener(const char* serviceName,
	uint32 eventMask, NotificationListener& listener)
{
	char buffer[96];
	KMessage specifier;
	specifier.SetTo(buffer, sizeof(buffer), 0);
	specifier.AddInt32(kEventMaskString, eventMask);

	return UpdateListener(serviceName, &specifier, listener);
}
コード例 #10
0
status_t
BPrivate::send_authentication_request_to_registrar(KMessage& request,
	KMessage& reply)
{
	status_t error = request.SendTo(get_registrar_authentication_port(), 0,
		&reply);
	if (error != B_OK)
		return error;

	return (status_t)reply.What();
}
コード例 #11
0
ファイル: notifications.cpp プロジェクト: AmirAbrams/haiku
status_t
notify_interface_removed(net_interface* interface)
{
	if (sNotificationModule == NULL)
		return B_NOT_SUPPORTED;

	char messageBuffer[512];
	KMessage message;
	message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
	message.AddInt32("opcode", B_NETWORK_INTERFACE_REMOVED);
	message.AddString("interface", interface->name);

	return sNotificationModule->send_notification(&message);
}
コード例 #12
0
ファイル: MessageAdapter.cpp プロジェクト: mariuz/haiku
status_t
MessageAdapter::Unflatten(uint32 format, BMessage *into, const char *buffer)
{
	if (format == KMessage::kMessageHeaderMagic) {
		KMessage message;
		status_t result = message.SetTo(buffer,
			((KMessage::Header *)buffer)->size);
		if (result != B_OK)
			return result;

		return _ConvertKMessage(&message, into);
	}

	try {
		switch (format) {
			case MESSAGE_FORMAT_R5:
			{
				r5_message_header *header = (r5_message_header *)buffer;
				BMemoryIO stream(buffer + sizeof(uint32),
					header->flattened_size - sizeof(uint32));
				return _UnflattenR5Message(format, into, &stream);
			}

			case MESSAGE_FORMAT_R5_SWAPPED:
			{
				r5_message_header *header = (r5_message_header *)buffer;
				BMemoryIO stream(buffer + sizeof(uint32),
					__swap_int32(header->flattened_size) - sizeof(uint32));
				return _UnflattenR5Message(format, into, &stream);
			}

			case MESSAGE_FORMAT_DANO:
			case MESSAGE_FORMAT_DANO_SWAPPED:
			{
				dano_section_header *header = (dano_section_header *)buffer;
				ssize_t size = header->size;
				if (header->code == MESSAGE_FORMAT_DANO_SWAPPED)
					size = __swap_int32(size);

				BMemoryIO stream(buffer + sizeof(uint32), size - sizeof(uint32));
				return _UnflattenDanoMessage(format, into, &stream);
			}
		}
	} catch (status_t error) {
		into->MakeEmpty();
		return error;
	}

	return B_NOT_A_MESSAGE;
}
コード例 #13
0
void KBattleshipWindow::slotSendMessage(int fieldx, int fieldy, int state)
{
	if(m_connection != 0)
	{
		KMessage *msg = new KMessage(KMessage::ANSWER_SHOOT);
		msg->addField(QString("fieldx"), QString::number(fieldx));
		msg->addField(QString("fieldy"), QString::number(fieldy));
		msg->addField(QString("fieldstate"), QString::number(state));

		if(m_connection->type() == KonnectionHandling::SERVER)
			m_kbserver->sendMessage(msg);
		else
			m_kbclient->sendMessage(msg);
	}
}
コード例 #14
0
// _RequestThread
int32
AuthenticationServer::_RequestThread()
{
	TaskManager taskManager;
	while (!fTerminating) {
		taskManager.RemoveDoneTasks();
		// read the request
		KMessage request;
		status_t error = request.ReceiveFrom(fRequestPort);
		if (error != B_OK)
			continue;
		// get the parameters
		const char* context = NULL;
		const char* server = NULL;
		const char* share = NULL;
		bool badPassword = true;
		request.FindString("context", &context);
		request.FindString("server", &server);
		request.FindString("share", &share);
		request.FindBool("badPassword", &badPassword);
		if (!context || !server || !share)
			continue;
		String foundUser;
		String foundPassword;
		if (!badPassword && _GetAuthentication(context, server, share,
			&foundUser, &foundPassword)) {
			_SendRequestReply(request.ReplyPort(), request.ReplyToken(),
				error, false, foundUser.GetString(), foundPassword.GetString());
		} else {
			// we need to ask the user: create a task that does it
			UserDialogTask* task = new(nothrow) UserDialogTask(this, context,
				server, share, badPassword, request.ReplyPort(),
				request.ReplyToken());
			if (!task) {
				ERROR(("AuthenticationServer::_RequestThread(): ERROR: "
					"failed to allocate "));
				continue;
			}
			status_t error = taskManager.RunTask(task);
			if (error != B_OK) {
				ERROR(("AuthenticationServer::_RequestThread(): Failed to "
					"start server info task: %s\n", strerror(error)));
				continue;
			}
		}
	}
	return 0;
}
コード例 #15
0
status_t
LocalDebuggerInterface::GetNextDebugEvent(DebugEvent*& _event)
{
	while (true) {
		char buffer[2048];
		int32 messageCode;
		ssize_t size = read_port(fDebuggerPort, &messageCode, buffer,
			sizeof(buffer));
		if (size < 0) {
			if (size == B_INTERRUPTED)
				continue;

			return size;
		}

		if (messageCode <= B_DEBUGGER_MESSAGE_HANDED_OVER) {
 			debug_debugger_message_data message;
			memcpy(&message, buffer, size);
			if (message.origin.team != fTeamID)
				continue;

			bool ignore = false;
			status_t error = _CreateDebugEvent(messageCode, message, ignore,
				_event);
			if (error != B_OK)
				return error;

			if (ignore) {
				if (message.origin.thread >= 0 && message.origin.nub_port >= 0)
					error = continue_thread(message.origin.nub_port,
						message.origin.thread);
				if (error != B_OK)
					return error;
				continue;
			}

			return B_OK;
		}

		KMessage message;
		size = message.SetTo(buffer);
		if (size != B_OK)
			return size;
		return _GetNextSystemWatchEvent(_event, message);
	}

	return B_OK;
}
コード例 #16
0
ファイル: ieee80211_haiku.cpp プロジェクト: sahil9912/haiku
void
ieee80211_notify_scan_done(struct ieee80211vap* vap)
{
	release_sem_etc(vap->iv_ifp->scan_done_sem, 1,
		B_DO_NOT_RESCHEDULE | B_RELEASE_ALL);

	TRACE("%s\n", __FUNCTION__);

	if (sNotificationModule != NULL) {
		char messageBuffer[512];
		KMessage message;
		message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
		message.AddInt32("opcode", B_NETWORK_WLAN_SCANNED);
		message.AddString("interface", vap->iv_ifp->device_name);

		sNotificationModule->send_notification(&message);
	}
}
コード例 #17
0
ファイル: grp.cpp プロジェクト: mariuz/haiku
void
endgrent(void)
{
	UserGroupLocker locker;

	sGroupDBReply.Unset();
	sGroupEntries = NULL;
	sGroupEntryCount = 0;
	sIterationIndex = 0;
}
コード例 #18
0
status_t
LocalDebuggerInterface::_GetNextSystemWatchEvent(DebugEvent*& _event,
	KMessage& message)
{
	status_t error = B_OK;
	if (message.What() != B_SYSTEM_OBJECT_UPDATE)
		return B_BAD_DATA;

	int32 opcode = 0;
	if (message.FindInt32("opcode", &opcode) != B_OK)
		return B_BAD_DATA;

	DebugEvent* event = NULL;
	switch (opcode)
	{
		case B_THREAD_NAME_CHANGED:
		{
			int32 threadID = -1;
			if (message.FindInt32("thread", &threadID) != B_OK)
				break;

			thread_info info;
			error = get_thread_info(threadID, &info);
			if (error != B_OK)
				break;

			event = new(std::nothrow) ThreadRenamedEvent(fTeamID,
				threadID, threadID, info.name);
			break;
		}

		default:
		{
			error = B_BAD_DATA;
			break;
		}
	}

	if (event != NULL)
		_event = event;

	return error;
}
コード例 #19
0
ファイル: shadow.cpp プロジェクト: mariuz/haiku
void
endspent(void)
{
	UserGroupLocker locker;

	sShadowPwdDBReply.Unset();
	sShadowPwdEntries = NULL;
	sShadowPwdEntryCount = 0;
	sIterationIndex = 0;
}
コード例 #20
0
ファイル: notifications.cpp プロジェクト: AmirAbrams/haiku
status_t
notify_interface_changed(net_interface* interface, uint32 oldFlags,
	uint32 newFlags)
{
	if (sNotificationModule == NULL)
		return B_NOT_SUPPORTED;

	char messageBuffer[512];
	KMessage message;
	message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
	message.AddInt32("opcode", B_NETWORK_INTERFACE_CHANGED);
	message.AddString("interface", interface->name);
	if (oldFlags != newFlags) {
		message.AddInt32("old flags", oldFlags);
		message.AddInt32("new flags", newFlags);
	}

	return sNotificationModule->send_notification(&message);
}
コード例 #21
0
ファイル: grp.cpp プロジェクト: mariuz/haiku
static status_t
query_group_entry(const char* name, gid_t _gid, struct group *group,
	char *buffer, size_t bufferSize, struct group **_result)
{
	*_result = NULL;

	KMessage message(BPrivate::B_REG_GET_GROUP);
	if (name)
		message.AddString("name", name);
	else
		message.AddInt32("gid", _gid);

	KMessage reply;
	status_t error = BPrivate::send_authentication_request_to_registrar(message,
		reply);
	if (error != B_OK)
		return error;

	int32 gid;
	const char* password;

	if ((error = reply.FindInt32("gid", &gid)) != B_OK
		|| (error = reply.FindString("name", &name)) != B_OK
		|| (error = reply.FindString("password", &password)) != B_OK) {
		return error;
	}

	const char* members[MAX_GROUP_MEMBER_COUNT];
	int memberCount = 0;
	for (int memberCount = 0; memberCount < MAX_GROUP_MEMBER_COUNT;) {
		if (reply.FindString("members", members + memberCount) != B_OK)
			break;
		memberCount++;
	}

	error = BPrivate::copy_group_to_buffer(name, password, gid, members,
		memberCount, group, buffer, bufferSize);
	if (error == B_OK)
		*_result = group;

	return error;
}
コード例 #22
0
ファイル: grp.cpp プロジェクト: mariuz/haiku
int
getgrouplist(const char* user, gid_t baseGroup, gid_t* groupList,
	int* groupCount)
{
	int maxGroupCount = *groupCount;
	*groupCount = 0;

	status_t error = B_OK;

	// prepare request
	KMessage message(BPrivate::B_REG_GET_USER_GROUPS);
	if (message.AddString("name", user) != B_OK
		|| message.AddInt32("max count", maxGroupCount) != B_OK) {
		return -1;
	}

	// send request
	KMessage reply;
	error = BPrivate::send_authentication_request_to_registrar(message, reply);
	if (error != B_OK)
		return -1;

	// unpack reply
	int32 count;
	const int32* groups;
	int32 groupsSize;
	if (reply.FindInt32("count", &count) != B_OK
		|| reply.FindData("groups", B_INT32_TYPE, (const void**)&groups,
				&groupsSize) != B_OK) {
		return -1;
	}

	memcpy(groupList, groups, groupsSize);
	*groupCount = count;

	// add the base group
	if (*groupCount < maxGroupCount)
		groupList[*groupCount] = baseGroup;
	++*groupCount;

	return *groupCount <= maxGroupCount ? *groupCount : -1;
}
コード例 #23
0
ファイル: grp.cpp プロジェクト: mariuz/haiku
static status_t
init_group_db()
{
	if (sGroupEntries != NULL)
		return B_OK;

	// ask the registrar
	KMessage message(BPrivate::B_REG_GET_GROUP_DB);
	status_t error = BPrivate::send_authentication_request_to_registrar(message,
		sGroupDBReply);
	if (error != B_OK)
		return error;

	// unpack the reply
	int32 count;
	group** entries;
	int32 numBytes;
	if ((error = sGroupDBReply.FindInt32("count", &count)) != B_OK
		|| (error = sGroupDBReply.FindData("entries", B_RAW_TYPE,
				(const void**)&entries, &numBytes)) != B_OK) {
		return error;
	}

	// relocate the entries
	addr_t baseAddress = (addr_t)entries;
	for (int32 i = 0; i < count; i++) {
		group* entry = relocate_pointer(baseAddress, entries[i]);
		relocate_pointer(baseAddress, entry->gr_name);
		relocate_pointer(baseAddress, entry->gr_passwd);
		relocate_pointer(baseAddress, entry->gr_mem);
		int32 k = 0;
		for (; entry->gr_mem[k] != (void*)-1; k++)
			relocate_pointer(baseAddress, entry->gr_mem[k]);
		entry->gr_mem[k] = NULL;
	}

	sGroupEntries = entries;
	sGroupEntryCount = count;

	return B_OK;
}
コード例 #24
0
ファイル: ieee80211_haiku.cpp プロジェクト: sahil9912/haiku
void
ieee80211_notify_node_leave(struct ieee80211_node* ni)
{
	struct ieee80211vap* vap = ni->ni_vap;
	struct ifnet* ifp = vap->iv_ifp;

	if (ni == vap->iv_bss)
		if_link_state_change(ifp, LINK_STATE_DOWN);

	TRACE("%s\n", __FUNCTION__);

	if (sNotificationModule != NULL) {
		char messageBuffer[512];
		KMessage message;
		message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
		message.AddInt32("opcode", B_NETWORK_WLAN_LEFT);
		message.AddString("interface", ifp->device_name);
		// TODO: add data about the node

		sNotificationModule->send_notification(&message);
	}
}
コード例 #25
0
ファイル: shadow.cpp プロジェクト: mariuz/haiku
int
getspnam_r(const char *name, struct spwd *spwd, char *buffer,
	size_t bufferSize, struct spwd **_result)
{
	*_result = NULL;

	KMessage message(BPrivate::B_REG_GET_USER);
	message.AddString("name", name);
	message.AddBool("shadow", true);

	KMessage reply;
	status_t error = BPrivate::send_authentication_request_to_registrar(message,
		reply);
	if (error != B_OK)
		return error;

	const char* password;
	int32 lastChanged;
	int32 min;
	int32 max;
	int32 warn;
	int32 inactive;
	int32 expiration;
	int32 flags;

	if ((error = reply.FindString("name", &name)) != B_OK
		|| (error = reply.FindString("shadow password", &password)) != B_OK
		|| (error = reply.FindInt32("last changed", &lastChanged)) != B_OK
		|| (error = reply.FindInt32("min", &min)) != B_OK
		|| (error = reply.FindInt32("max", &max)) != B_OK
		|| (error = reply.FindInt32("warn", &warn)) != B_OK
		|| (error = reply.FindInt32("inactive", &inactive)) != B_OK
		|| (error = reply.FindInt32("expiration", &expiration)) != B_OK
		|| (error = reply.FindInt32("flags", &flags)) != B_OK) {
		return error;
	}

	error = BPrivate::copy_shadow_pwd_to_buffer(name, password, lastChanged,
		min, max, warn, inactive, expiration, flags, spwd, buffer, bufferSize);
	if (error == B_OK)
		*_result = spwd;

	return error;
}
コード例 #26
0
ファイル: Shell.cpp プロジェクト: sahil9912/haiku
bool
Shell::GetActiveProcessInfo(ActiveProcessInfo& _info) const
{
	_info.Unset();

	// get the foreground process group
	pid_t process = tcgetpgrp(fFd);
	if (process < 0)
		return false;

	// get more info on the process group leader
	KMessage info;
	status_t error = get_extended_team_info(process, B_TEAM_INFO_BASIC, info);
	if (error != B_OK)
		return false;

	// fetch the name and the current directory from the info
	const char* name;
	int32 cwdDevice;
	int64 cwdDirectory;
	if (info.FindString("name", &name) != B_OK
		|| info.FindInt32("cwd device", &cwdDevice) != B_OK
		|| info.FindInt64("cwd directory", &cwdDirectory) != B_OK) {
		return false;
	}

	// convert the node ref into a path
	entry_ref cwdRef(cwdDevice, cwdDirectory, ".");
	BPath cwdPath;
	if (cwdPath.SetTo(&cwdRef) != B_OK)
		return false;

	// set the result
	_info.SetTo(process, name, cwdPath.Path());

	return true;
}
コード例 #27
0
ファイル: shadow.cpp プロジェクト: mariuz/haiku
static status_t
init_shadow_pwd_db()
{
	if (sShadowPwdEntries != NULL)
		return B_OK;

	// ask the registrar
	KMessage message(BPrivate::B_REG_GET_SHADOW_PASSWD_DB);
	status_t error = BPrivate::send_authentication_request_to_registrar(message,
		sShadowPwdDBReply);
	if (error != B_OK)
		return error;

	// unpack the reply
	int32 count;
	spwd** entries;
	int32 numBytes;
	if ((error = sShadowPwdDBReply.FindInt32("count", &count)) != B_OK
		|| (error = sShadowPwdDBReply.FindData("entries", B_RAW_TYPE,
				(const void**)&entries, &numBytes)) != B_OK) {
		return error;
	}

	// relocate the entries
	addr_t baseAddress = (addr_t)entries;
	for (int32 i = 0; i < count; i++) {
		spwd* entry = relocate_pointer(baseAddress, entries[i]);
		relocate_pointer(baseAddress, entry->sp_namp);
		relocate_pointer(baseAddress, entry->sp_pwdp);
	}

	sShadowPwdEntries = entries;
	sShadowPwdEntryCount = count;

	return B_OK;
}
コード例 #28
0
	void _SendMessage(messaging_target* targets, int32 targetCount,
		int32 object, uint32 opcode)
	{
		// prepare the message
		char buffer[128];
		KMessage message;
		message.SetTo(buffer, sizeof(buffer), B_SYSTEM_OBJECT_UPDATE);
		message.AddInt32("opcode", opcode);
		if (opcode < B_THREAD_CREATED)
			message.AddInt32("team", object);
		else
			message.AddInt32("thread", object);

		// send it
		send_message(message.Buffer(), message.ContentSize(), targets,
			targetCount);
	}
コード例 #29
0
ファイル: notifications.cpp プロジェクト: AmirAbrams/haiku
status_t
notify_link_changed(net_device* device)
{
	if (sNotificationModule == NULL)
		return B_NOT_SUPPORTED;

	char messageBuffer[512];
	KMessage message;
	message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
	message.AddInt32("opcode", B_NETWORK_DEVICE_LINK_CHANGED);
	message.AddString("device", device->name);
	message.AddInt32("media", device->media);
	message.AddInt64("link speed", device->link_speed);
	message.AddInt32("link quality", device->link_quality);

	return sNotificationModule->send_notification(&message);
}
コード例 #30
0
// _SendRequestReply
status_t
AuthenticationServer::_SendRequestReply(port_id port, int32 token,
	status_t error, bool cancelled, const char* user, const char* password)
{
	// prepare the reply
	KMessage reply;
	reply.AddInt32("error", error);
	if (error == B_OK) {
		reply.AddBool("cancelled", cancelled);
		if (!cancelled) {
			reply.AddString("user", user);
			reply.AddString("password", password);
		}
	}
	// send the reply
	return reply.SendTo(port, token);
}