diff options
author | David Robillard <d@drobilla.net> | 2009-05-29 00:44:49 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-05-29 00:44:49 +0000 |
commit | 085f5e9c5eec12171596c47c0b70f6634dbc1402 (patch) | |
tree | 16df3f452c174bbd1f1099936dc592939a59967e /src/engine | |
parent | b3c31c94eb572063ec97f24a89e5f7f98d5eae41 (diff) | |
download | ingen-085f5e9c5eec12171596c47c0b70f6634dbc1402.tar.gz ingen-085f5e9c5eec12171596c47c0b70f6634dbc1402.tar.bz2 ingen-085f5e9c5eec12171596c47c0b70f6634dbc1402.zip |
Node creation via HTTP.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2045 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/HTTPClientSender.cpp | 29 | ||||
-rw-r--r-- | src/engine/HTTPEngineReceiver.cpp | 15 | ||||
-rw-r--r-- | src/engine/QueuedEngineInterface.cpp | 9 |
3 files changed, 32 insertions, 21 deletions
diff --git a/src/engine/HTTPClientSender.cpp b/src/engine/HTTPClientSender.cpp index 6735c164..d77f684e 100644 --- a/src/engine/HTTPClientSender.cpp +++ b/src/engine/HTTPClientSender.cpp @@ -16,6 +16,7 @@ */ #include <string> +#include <libsoup/soup.h> #include "raul/Atom.hpp" #include "raul/AtomRDF.hpp" #include "serialisation/Serialiser.hpp" @@ -28,17 +29,18 @@ using namespace Raul; namespace Ingen { +using namespace Shared; + void HTTPClientSender::response_ok(int32_t id) { - cout << "HTTP OK" << endl; } void HTTPClientSender::response_error(int32_t id, const std::string& msg) { - cout << "HTTP ERROR" << endl; + cout << "HTTP ERROR " << id << ": " << msg << endl; } @@ -50,10 +52,21 @@ HTTPClientSender::error(const std::string& msg) void -HTTPClientSender::put(const URI& path, - const Shared::Resource::Properties& properties) +HTTPClientSender::put(const URI& uri, + const Resource::Properties& properties) { - cerr << "HTTP CLIENT PUT " << path << endl; + const string path = (uri.substr(0, 6) == "path:/") ? uri.substr(6) : uri.str(); + const string full_uri = _url + "/" + path; + + Redland::Model model(*_engine.world()->rdf_world); + for (Resource::Properties::const_iterator i = properties.begin(); i != properties.end(); ++i) + model.add_statement( + Redland::Resource(*_engine.world()->rdf_world, path), + i->first.str(), + AtomRDF::atom_to_node(*_engine.world()->rdf_world, i->second)); + + const string str = model.serialise_to_string(); + send_chunk(str); } @@ -138,16 +151,16 @@ HTTPClientSender::activity(const Path& path) } #if 0 -static void null_deleter(const Shared::GraphObject*) {} +static void null_deleter(const GraphObject*) {} bool -HTTPClientSender::new_object(const Shared::GraphObject* object) +HTTPClientSender::new_object(const GraphObject* object) { SharedPtr<Serialisation::Serialiser> serialiser = _engine.world()->serialiser; serialiser->start_to_string("/", ""); // FIXME: kludge // FIXME: engine boost dependency? - boost::shared_ptr<Shared::GraphObject> obj((Shared::GraphObject*)object, null_deleter); + boost::shared_ptr<GraphObject> obj((GraphObject*)object, null_deleter); serialiser->serialise(obj); string str = serialiser->finish(); send_chunk(str); diff --git a/src/engine/HTTPEngineReceiver.cpp b/src/engine/HTTPEngineReceiver.cpp index 61d74ada..b2d3ca99 100644 --- a/src/engine/HTTPEngineReceiver.cpp +++ b/src/engine/HTTPEngineReceiver.cpp @@ -153,6 +153,7 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const soup_message_set_status(msg, SOUP_STATUS_OK); soup_message_set_response(msg, mime_type, SOUP_MEMORY_COPY, r.c_str(), r.length()); return; + } else if (path.substr(0, 6) == "/patch") { path = '/' + path.substr(6); @@ -167,15 +168,10 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const soup_message_set_status(msg, SOUP_STATUS_OK); soup_message_set_response(msg, mime_type, SOUP_MEMORY_COPY, buf, strlen(buf)); return; - - } else { - soup_message_set_status(msg, SOUP_STATUS_NOT_FOUND); - soup_message_set_response(msg, "text/plain", SOUP_MEMORY_STATIC, - "Unknown path\n\n", 14); - return; } if (!Path::is_valid(path)) { + cerr << "HTTP BAD REQUEST" << endl; soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST); const string& err = (boost::format("Bad path: %1%") % path).str(); soup_message_set_response(msg, "text/plain", SOUP_MEMORY_COPY, @@ -223,6 +219,7 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const // Be sure object doesn't exist Store::const_iterator start = store->find(path); if (start != store->end()) { + cerr << "HTTP CONFLICT" << endl; soup_message_set_status(msg, SOUP_STATUS_CONFLICT); return; } @@ -230,16 +227,18 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const // Get parser SharedPtr<Parser> parser = me->_engine.world()->parser; if (!parser) { + cerr << "HTTP INTERNAL ERROR" << endl; soup_message_set_status(msg, SOUP_STATUS_INTERNAL_SERVER_ERROR); return; } - //cout << "POST: " << msg->request_body->data << endl; + parser->parse_string(me->_engine.world(), me, msg->request_body->data, ""); // Load object soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); + } else if (msg->method == SOUP_METHOD_POST) { - //cout << "PUT: " << msg->request_body->data << endl; + cout << "POST" << endl; soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); } else { soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); diff --git a/src/engine/QueuedEngineInterface.cpp b/src/engine/QueuedEngineInterface.cpp index cce6bb9d..4873f21b 100644 --- a/src/engine/QueuedEngineInterface.cpp +++ b/src/engine/QueuedEngineInterface.cpp @@ -155,17 +155,16 @@ void QueuedEngineInterface::put(const URI& uri, const Resource::Properties& properties) { - size_t hash = uri.find("#"); - bool meta = (hash != string::npos); - Path path(meta ? (string("/") + uri.chop_start("#")) : uri.str()); + bool meta = uri.substr(0, 6) == "meta:#"; + URI subject(meta ? (string("path:/") + uri.substr(6)) : uri.str()); + /*cerr << "ENGINE PUT " << subject << " {" << endl; typedef Resource::Properties::const_iterator iterator; - /*cerr << "ENGINE PUT " << path << " (" << path << ") {" << endl; for (iterator i = properties.begin(); i != properties.end(); ++i) cerr << "\t" << i->first << " = " << i->second << " :: " << i->second.type() << endl; cerr << "}" << endl;*/ - push_queued(new SetMetadataEvent(_engine, _responder, now(), this, meta, path, properties)); + push_queued(new SetMetadataEvent(_engine, _responder, now(), this, meta, subject, properties)); } |