first cut at domain server config support

This commit is contained in:
ZappoMan 2013-09-17 12:18:46 -07:00
parent 00506b1a84
commit 48a579ae49

View file

@ -27,7 +27,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QtCore/QMap>
#include <QtCore/QMutex> #include <QtCore/QMutex>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <civetweb.h> #include <civetweb.h>
@ -45,6 +48,7 @@ const int NODE_COUNT_STAT_INTERVAL_MSECS = 5000;
QMutex assignmentQueueMutex; QMutex assignmentQueueMutex;
std::deque<Assignment*> assignmentQueue; std::deque<Assignment*> assignmentQueue;
QMap<QString, QString> configMap;
unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd) { unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd) {
*currentPosition++ = nodeToAdd->getType(); *currentPosition++ = nodeToAdd->getType();
@ -66,6 +70,37 @@ static int mongooseRequestHandler(struct mg_connection *conn) {
// upload the file // upload the file
mg_upload(conn, "/tmp"); mg_upload(conn, "/tmp");
return 1;
} else if (strncmp(ri->uri, "/config", strlen("/config")) == 0 && strcmp(ri->request_method, "GET") == 0) {
// Let's split up the URL into it's pieces so we can service it
QString uri(ri->uri);
QString delimiterPattern("/");
QStringList uriParts = uri.split(delimiterPattern);
QString configGuid = uriParts[2];
// first part should be empty
// second part should be "config"
// third part should be a guid, and therefore should not be empty
if (!uriParts[0].isEmpty() || uriParts[1] != "config" || configGuid.isEmpty()) {
mg_printf(conn, "%s", "HTTP/1.0 400 Bad Request\r\nContent-Type: text/plain\r\n\r\nInvalid parameters.");
return 1;
}
// assuming the request format was valid, look up the guid in our configs
if (!::configMap.contains(configGuid)) {
mg_printf(conn, "%s", "HTTP/1.0 404 Not Found\r\nContent-Type: text/plain\r\n\r\nInvalid config GUID.");
return 1;
}
const char * configPayload = configMap[configGuid].toLocal8Bit().data();
// return a 200
mg_printf(conn, "%s", "HTTP/1.0 200 OK\r\n\r\n");
// return the configuration "payload"
mg_printf(conn, "%s", configPayload);
return 1; return 1;
} else { } else {
// have mongoose process this request from the document_root // have mongoose process this request from the document_root