Example #1
0
/*
 * Phdc Manager requests to be removed from the existing list of managers.
 */
static DBusMessage *dbus_unregister_phdc_agent(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct near_phdc_data *mgr;
	DBusMessageIter iter;
	const char *path, *role, *sender;

	DBG("conn %p", conn);

	if (!dbus_message_iter_init(msg, &iter))
		return error_invalid_arguments(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
		return error_invalid_arguments(msg);

	sender = dbus_message_get_sender(msg);

	dbus_message_iter_get_basic(&iter, &path);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return error_invalid_arguments(msg);

	dbus_message_iter_get_basic(&iter, &role);

	/* look for specific path */
	mgr = search_mgr_list_by_path(path);
	if (!mgr)
		return error_not_found(msg);

	DBG("%s", mgr->sender);

	if (strncmp(sender, mgr->sender, strlen(mgr->sender)))
		return error_permission_denied(msg);

	/* remove it */
	near_p2p_unregister(mgr->p2p_driver);

	g_hash_table_remove(mgr_list, mgr->p2p_driver->service_name);

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
Example #2
0
File: ls.c Project: gmpetrov/ft_p
void	ls(int cs, char *buf)
{
	char			**tab;
	DIR				*dir;
	struct dirent	*sd;

	tab = ft_strsplit(buf, ' ');
	if (ft_strcmp(tab[0], "ls") == 0 && !tab[1])
	{
		send(cs, "\033[32mSUCCESS\033[0m\n", 19, MSG_OOB);
		dir = opendir(".");
		while ((sd = readdir(dir)) != NULL)
		{
			send(cs, sd->d_name, ft_strlen(sd->d_name) + 1, MSG_OOB);
			send(cs, "\n", 2, MSG_OOB);
		}
		closedir(dir);
	}
	else
		error_not_found(cs);
	if (tab)
		free(tab);
}