summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-05-29 01:46:22 +0000
committerDavid Robillard <d@drobilla.net>2009-05-29 01:46:22 +0000
commit5245a25bafec9372d07c346457d473cfa76724df (patch)
tree1336a5bff4fbdd4179268df63dd486407e7a14cd
parent92a48b741ca3eb8698e6ae8f4f6923583d42cd66 (diff)
downloadingen-5245a25bafec9372d07c346457d473cfa76724df.tar.gz
ingen-5245a25bafec9372d07c346457d473cfa76724df.tar.bz2
ingen-5245a25bafec9372d07c346457d473cfa76724df.zip
DELETE via HTTP.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2047 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/client/HTTPEngineSender.cpp8
-rw-r--r--src/engine/HTTPEngineReceiver.cpp97
2 files changed, 47 insertions, 58 deletions
diff --git a/src/client/HTTPEngineSender.cpp b/src/client/HTTPEngineSender.cpp
index fa3509f6..abf51a56 100644
--- a/src/client/HTTPEngineSender.cpp
+++ b/src/client/HTTPEngineSender.cpp
@@ -130,7 +130,7 @@ HTTPEngineSender::put(const URI& uri,
AtomRDF::atom_to_node(_world, i->second));
const string str = model.serialise_to_string();
- SoupMessage* msg = soup_message_new("PUT", full_uri.c_str());
+ SoupMessage* msg = soup_message_new(SOUP_METHOD_PUT, full_uri.c_str());
assert(msg);
soup_message_set_request(msg, "application/x-turtle", SOUP_MEMORY_COPY, str.c_str(), str.length());
soup_session_send_message(_session, msg);
@@ -145,8 +145,12 @@ HTTPEngineSender::move(const Path& old_path,
void
-HTTPEngineSender::del(const Path& path)
+HTTPEngineSender::del(const Path& uri)
{
+ const string path = (uri.substr(0, 6) == "path:/") ? uri.substr(6) : uri.str();
+ const string full_uri = _engine_url.str() + "/" + path;
+ SoupMessage* msg = soup_message_new(SOUP_METHOD_DELETE, full_uri.c_str());
+ soup_session_send_message(_session, msg);
}
diff --git a/src/engine/HTTPEngineReceiver.cpp b/src/engine/HTTPEngineReceiver.cpp
index d4c0ac1e..532a4371 100644
--- a/src/engine/HTTPEngineReceiver.cpp
+++ b/src/engine/HTTPEngineReceiver.cpp
@@ -127,51 +127,50 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const
const string base_uri = "path:/";
const char* mime_type = "text/plain";
- if (!strcmp(msg->method, SOUP_METHOD_PUT)) {
- cout << "PUT " << path << ":\n" << msg->request_body->data << endl;
- }
-
- if (path == Path::root_uri || path == "") {
- const string r = string("@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n")
- .append("\n<> rdfs:seeAlso <plugins> ;")
- .append("\n rdfs:seeAlso <stream> ;")
- .append("\n rdfs:seeAlso <patch> .");
- 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, 8) == "/plugins") {
- // FIXME: kludge
- me->load_plugins();
- me->_receive_thread->whip();
+ // Special GET paths
+ if (msg->method == SOUP_METHOD_GET) {
+ if (path == Path::root_uri || path == "") {
+ const string r = string("@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n")
+ .append("\n<> rdfs:seeAlso <plugins> ;")
+ .append("\n rdfs:seeAlso <stream> ;")
+ .append("\n rdfs:seeAlso <patch> .");
+ soup_message_set_status(msg, SOUP_STATUS_OK);
+ soup_message_set_response(msg, mime_type, SOUP_MEMORY_COPY, r.c_str(), r.length());
+ return;
- serialiser->start_to_string("/", base_uri);
- for (NodeFactory::Plugins::const_iterator p = me->_engine.node_factory()->plugins().begin();
- p != me->_engine.node_factory()->plugins().end(); ++p)
- serialiser->serialise_plugin(*(Shared::Plugin*)p->second);
- const string r = serialiser->finish();
- 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 (msg->method == SOUP_METHOD_GET && path.substr(0, 8) == "/plugins") {
+ // FIXME: kludge
+ me->load_plugins();
+ me->_receive_thread->whip();
+
+ serialiser->start_to_string("/", base_uri);
+ for (NodeFactory::Plugins::const_iterator p = me->_engine.node_factory()->plugins().begin();
+ p != me->_engine.node_factory()->plugins().end(); ++p)
+ serialiser->serialise_plugin(*(Shared::Plugin*)p->second);
+ const string r = serialiser->finish();
+ 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);
+ } else if (path.substr(0, 6) == "/patch") {
+ path = '/' + path.substr(6);
- } else if (path.substr(0, 7) == "/stream") {
- HTTPClientSender* client = new HTTPClientSender(me->_engine);
- me->register_client(client);
+ } else if (path.substr(0, 7) == "/stream") {
+ HTTPClientSender* client = new HTTPClientSender(me->_engine);
+ me->register_client(client);
- // Respond with port number of stream for client
- const int port = client->listen_port();
- char buf[32];
- snprintf(buf, 32, "%d", port);
- soup_message_set_status(msg, SOUP_STATUS_OK);
- soup_message_set_response(msg, mime_type, SOUP_MEMORY_COPY, buf, strlen(buf));
- return;
+ // Respond with port number of stream for client
+ const int port = client->listen_port();
+ char buf[32];
+ snprintf(buf, 32, "%d", port);
+ soup_message_set_status(msg, SOUP_STATUS_OK);
+ soup_message_set_response(msg, mime_type, SOUP_MEMORY_COPY, buf, strlen(buf));
+ return;
+ }
}
if (!Path::is_valid(path)) {
- cerr << "HTTP BAD REQUEST" << endl;
+ cerr << "HTTP BAD PATH: " << path << 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,
@@ -201,10 +200,6 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const
return;
}
- /*SoupMessageHeaders* in_head = msg->request_headers;
- const char* str = soup_message_headers_get(in_head, "Accept");
- cout << "Accept: " << str << endl;*/
-
// Serialise object
const string response = serialiser->to_string(start->second,
"http://localhost:16180/patch", GraphObject::Properties());
@@ -216,30 +211,20 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const
} else if (msg->method == SOUP_METHOD_PUT) {
Glib::RWLock::WriterLock lock(store->lock());
- // 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;
- }
-
// 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;
}
parser->parse_string(me->_engine.world(), me, msg->request_body->data, base_uri);
+ soup_message_set_status(msg, SOUP_STATUS_OK);
- // Load object
- soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
+ } else if (msg->method == SOUP_METHOD_DELETE) {
+ me->del(path);
+ soup_message_set_status(msg, SOUP_STATUS_OK);
- } else if (msg->method == SOUP_METHOD_POST) {
- cout << "POST" << endl;
- soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
} else {
soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
}