summaryrefslogtreecommitdiffstats
path: root/src/engine/HTTPEngineReceiver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/HTTPEngineReceiver.cpp')
-rw-r--r--src/engine/HTTPEngineReceiver.cpp97
1 files changed, 41 insertions, 56 deletions
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);
}