From a9a55b0ddcb2223fc1ba0a5a47f357955bb1a42e Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 19 Sep 2010 03:06:31 +0300 Subject: [PATCH] daemon: refuse to create room with duplicate name. Fix for #106 --- daemon/cmd_create_room.c | 7 +++++++ daemon/studio.c | 17 +++++++++++++++++ daemon/studio.h | 1 + 3 files changed, 25 insertions(+) diff --git a/daemon/cmd_create_room.c b/daemon/cmd_create_room.c index 99d2753a..e44af371 100644 --- a/daemon/cmd_create_room.c +++ b/daemon/cmd_create_room.c @@ -28,6 +28,7 @@ #include "studio_internal.h" #include "../dbus/error.h" #include "control.h" +#include "../proxies/notify_proxy.h" struct ladish_command_create_room { @@ -53,6 +54,12 @@ static bool run(void * cmd_context) goto fail; } + if (ladish_studio_check_room_name(cmd_ptr->room_name)) + { + ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH, "Room with requested name already exists", cmd_ptr->room_name); + goto fail; + } + if (!ladish_room_create(NULL, cmd_ptr->room_name, room, g_studio.studio_graph, &room)) { log_error("ladish_room_create() failed."); diff --git a/daemon/studio.c b/daemon/studio.c index f712c412..8424a5fb 100644 --- a/daemon/studio.c +++ b/daemon/studio.c @@ -1009,6 +1009,23 @@ ladish_room_handle ladish_studio_find_room_by_uuid(const uuid_t room_uuid_ptr) return NULL; } +bool ladish_studio_check_room_name(const char * room_name) +{ + struct list_head * node_ptr; + ladish_room_handle room; + + list_for_each(node_ptr, &g_studio.rooms) + { + room = ladish_room_from_list_node(node_ptr); + if (strcmp(ladish_room_get_name(room), room_name) == 0) + { + return true; + } + } + + return false; +} + /**********************************************************************************/ /* D-Bus methods */ /**********************************************************************************/ diff --git a/daemon/studio.h b/daemon/studio.h index 621bd27e..47dc0645 100644 --- a/daemon/studio.h +++ b/daemon/studio.h @@ -74,5 +74,6 @@ void ladish_studio_room_appeared(ladish_room_handle room); void ladish_studio_room_disappeared(ladish_room_handle room); ladish_room_handle ladish_studio_find_room_by_uuid(const uuid_t room_uuid_ptr); +bool ladish_studio_check_room_name(const char * room_name); #endif /* #ifndef STUDIO_H__0BEDE85E_4FB3_4D74_BC08_C373A22409C0__INCLUDED */