From 640cbadb284544ecc876ae650c1c945c57adcce8 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 18 Aug 2008 03:58:03 +0000 Subject: Tolerate attempts to create patches with illegal paths. git-svn-id: http://svn.drobilla.net/lad/ingen@1429 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/events/CreatePatchEvent.cpp | 20 ++++++++++++++++---- src/libs/engine/events/CreatePatchEvent.hpp | 14 +++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/libs/engine/events/CreatePatchEvent.cpp b/src/libs/engine/events/CreatePatchEvent.cpp index e054412f..6279732e 100644 --- a/src/libs/engine/events/CreatePatchEvent.cpp +++ b/src/libs/engine/events/CreatePatchEvent.cpp @@ -45,6 +45,12 @@ CreatePatchEvent::CreatePatchEvent(Engine& engine, SharedPtr responde void CreatePatchEvent::pre_process() { + if (!Path::is_valid(_path)) { + _error = INVALID_PATH; + QueuedEvent::pre_process(); + return; + } + if (_path == "/" || _engine.engine_store()->find_object(_path) != NULL) { _error = OBJECT_EXISTS; QueuedEvent::pre_process(); @@ -57,7 +63,9 @@ CreatePatchEvent::pre_process() return; } - _parent = _engine.engine_store()->find_patch(_path.parent()); + const Path& path = (const Path&)_path; + + _parent = _engine.engine_store()->find_patch(path.parent()); if (_parent == NULL) { _error = PARENT_NOT_FOUND; QueuedEvent::pre_process(); @@ -68,7 +76,7 @@ CreatePatchEvent::pre_process() if (_parent != NULL && _poly > 1 && _poly == static_cast(_parent->internal_polyphony())) poly = _poly; - _patch = new PatchImpl(_engine, _path.name(), poly, _parent, _engine.audio_driver()->sample_rate(), _engine.audio_driver()->buffer_size(), _poly); + _patch = new PatchImpl(_engine, path.name(), poly, _parent, _engine.audio_driver()->sample_rate(), _engine.audio_driver()->buffer_size(), _poly); if (_parent != NULL) { _parent->add_node(new PatchImpl::Nodes::Node(_patch)); @@ -121,13 +129,17 @@ CreatePatchEvent::post_process() // (otherwise they would be sent twice) _engine.broadcaster()->send_patch(_patch, false); + } else if (_error == INVALID_PATH) { + string msg = "Attempt to create patch with illegal path "; + msg.append(_path); + _responder->respond_error(msg); } else if (_error == OBJECT_EXISTS) { string msg = "Unable to create patch: "; - msg += _path += " already exists."; + msg.append(_path).append(" already exists."); _responder->respond_error(msg); } else if (_error == PARENT_NOT_FOUND) { string msg = "Unable to create patch: Parent "; - msg += _path.parent() += " not found."; + msg.append(Path(_path).parent()).append(" not found."); _responder->respond_error(msg); } else if (_error == INVALID_POLY) { string msg = "Unable to create patch "; diff --git a/src/libs/engine/events/CreatePatchEvent.hpp b/src/libs/engine/events/CreatePatchEvent.hpp index bcbcf35b..733aba17 100644 --- a/src/libs/engine/events/CreatePatchEvent.hpp +++ b/src/libs/engine/events/CreatePatchEvent.hpp @@ -47,14 +47,14 @@ public: void post_process(); private: - enum ErrorType { NO_ERROR, OBJECT_EXISTS, PARENT_NOT_FOUND, INVALID_POLY }; + enum ErrorType { NO_ERROR, OBJECT_EXISTS, PARENT_NOT_FOUND, INVALID_POLY, INVALID_PATH }; - Raul::Path _path; - PatchImpl* _patch; - PatchImpl* _parent; - CompiledPatch* _compiled_patch; - int _poly; - ErrorType _error; + const std::string _path; + PatchImpl* _patch; + PatchImpl* _parent; + CompiledPatch* _compiled_patch; + int _poly; + ErrorType _error; }; -- cgit v1.2.1